Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #173 from irisnet/develop
Browse files Browse the repository at this point in the history
R4R: prepare release v0.14.2
  • Loading branch information
weichang-x authored Jul 4, 2019
2 parents 68cf0b4 + 2b801c6 commit 138a7d2
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 244 deletions.
9 changes: 1 addition & 8 deletions conf/server/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

var (
BlockChainMonitorUrl = []string{"tcp://35.201.147.145:30657"}
ChainId = "fuxi"

WorkerNumCreateTask = 2
WorkerNumExecuteTask = 60
Expand All @@ -32,12 +31,6 @@ func init() {

logger.Info("Env Value", logger.Any(constant.EnvNameSerNetworkFullNode, BlockChainMonitorUrl))

chainId, found := os.LookupEnv(constant.EnvNameSerNetworkChainId)
if found {
ChainId = chainId
}
logger.Info("Env Value", logger.String(constant.EnvNameSerNetworkChainId, ChainId))

workerNumCreateTask, found := os.LookupEnv(constant.EnvNameWorkerNumCreateTask)
if found {
var err error
Expand All @@ -62,5 +55,5 @@ func init() {
if found {
Network = network
}
logger.Info("Env Value", logger.String(constant.EnvNameNetwork, network))
logger.Info("Env Value", logger.String(constant.EnvNameNetwork, Network))
}
14 changes: 0 additions & 14 deletions script/mongodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,19 @@

// create collections
db.createCollection("block");
db.createCollection("stake_role_candidate");
db.createCollection("sync_task");
db.createCollection("tx_common");
db.createCollection("proposal");
db.createCollection("tx_msg");
db.createCollection("power_change");//explorer
db.createCollection("uptime_change");
db.createCollection("sync_conf");
db.createCollection("mgo_txn");
db.createCollection("mgo_txn.stash");
db.createCollection("ex_tx_num_stat");



// create index
db.account.createIndex({"address": 1}, {"unique": true});
db.block.createIndex({"height": -1}, {"unique": true});

db.stake_role_candidate.createIndex({"address": 1}, {"unique": true});
db.stake_role_candidate.createIndex({"pub_key": 1});

db.sync_task.createIndex({"start_height": 1, "end_height": 1}, {"unique": true});
db.sync_task.createIndex({"status": 1}, {"background": true});

Expand All @@ -43,9 +35,6 @@ db.tx_common.createIndex({"type": 1});
db.tx_common.createIndex({"status": 1});
db.tx_common.createIndex({"proposal_id": 1}, {"background": true});

db.power_change.createIndex({"height": 1, "address": 1}, {"unique": true});


db.proposal.createIndex({"proposal_id": 1}, {"unique": true});
db.proposal.createIndex({"status": 1}, {"background": true});
db.proposal.createIndex({"voting_end_time": 1, "deposit_end_time": 1, "status": 1}, {"background": true});
Expand All @@ -58,9 +47,7 @@ db.sync_conf.insert({"block_num_per_worker_handle": 50, "max_worker_sleep_time":
// drop collection
// db.account.drop();
// db.block.drop();
// db.power_change.drop();
// db.proposal.drop();
// db.stake_role_candidate.drop();
// db.sync_task.drop();
// db.tx_common.drop();
// db.tx_msg.drop();
Expand All @@ -71,7 +58,6 @@ db.sync_conf.insert({"block_num_per_worker_handle": 50, "max_worker_sleep_time":
// db.account.remove({});
// db.block.remove({});
// db.proposal.remove({});
// db.stake_role_candidate.remove({});
// db.sync_task.remove({});
// db.tx_common.remove({});
// db.tx_msg.remove({});
Expand Down
20 changes: 16 additions & 4 deletions service/handler/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
itypes "github.com/irisnet/irishub-sync/types"
"github.com/irisnet/irishub-sync/util/helper"
"strings"
"github.com/irisnet/irishub-sync/store"
)

var (
Expand Down Expand Up @@ -36,10 +37,11 @@ func ParseBlock(meta *types.BlockMeta, block *types.Block, validators []*types.V
}

docBlock := document.Block{
Height: meta.Header.Height,
Hash: hexFunc(meta.BlockID.Hash),
Time: meta.Header.Time,
NumTxs: meta.Header.NumTxs,
Height: meta.Header.Height,
Hash: hexFunc(meta.BlockID.Hash),
Time: meta.Header.Time,
NumTxs: meta.Header.NumTxs,
ProposalAddress: block.Header.ProposerAddress.String(),
}

lastBlockId := document.BlockID{
Expand Down Expand Up @@ -127,6 +129,16 @@ func ParseBlock(meta *types.BlockMeta, block *types.Block, validators []*types.V
docBlock.Validators = vals
docBlock.Result = parseBlockResult(docBlock.Height)

if proposalId,ok := IsContainVotingEndTag(docBlock.Result.EndBlock);ok {
if proposal,err := document.QueryProposal(proposalId);err == nil {
proposal.VotingEndHeight = docBlock.Height
store.SaveOrUpdate(proposal)
}else{
logger.Error("QueryProposal fail", logger.Int64("block", docBlock.Height),
logger.String("err", err.Error()))
}
}

// save or update account balance info and unbonding delegation info by parse block coin flow
accsBalanceNeedUpdated, accsUnbondingDelegationNeedUpdated := getAccountsFromCoinFlow(
docBlock.Result.EndBlock.Tags, docBlock.Height)
Expand Down
23 changes: 23 additions & 0 deletions service/handler/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,26 @@ func TestParseBlockResult(t *testing.T) {
bz, _ := json.Marshal(v)
fmt.Println(string(bz))
}

func TestParseBlock(t *testing.T) {
blockHeight := int64(88)

client := helper.GetClient()
defer client.Release()

if res, err := client.Block(&blockHeight); err != nil {
t.Fatal(err)
} else {
var validators []*types.Validator
valRes, err := client.Validators(&blockHeight)
if err != nil {
t.Error(err)
} else {
validators = valRes.Validators
}
blockDoc := ParseBlock(res.BlockMeta, res.Block, validators, nil)

resBytes, _ := json.MarshalIndent(blockDoc, "", "\t")
t.Log(string(resBytes))
}
}
15 changes: 15 additions & 0 deletions service/handler/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/irisnet/irishub-sync/types"
"github.com/irisnet/irishub-sync/util/constant"
"github.com/irisnet/irishub-sync/util/helper"
"strconv"
)

func handleProposal(docTx document.CommonTx) {
Expand Down Expand Up @@ -72,3 +73,17 @@ func isContainVotingPeriodStartTag(docTx document.CommonTx) bool {

return false
}

func IsContainVotingEndTag(blockresult document.ResponseEndBlock) (uint64, bool) {
tags := blockresult.Tags
if len(tags) > 0 {
for _, tag := range tags {
if tag.Key == constant.BlockTagProposalId {
proposalid,_ := strconv.ParseUint(tag.Value,10,64)
return proposalid, true
}
}
}

return 0, false
}
4 changes: 2 additions & 2 deletions service/handler/proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestIsContainVotingPeriodStartTag(t *testing.T) {
txHash := "A837138C2A569B7884AA94C27CC4AB791C04F1B8DD93EFC3D5BFCF3D7EB0F2F3"
txHash := "37A0127A87AA68BFE73D03C2B9A2A6A3D8E51DF242D86C845DB2D158B1617502"

var tx document.CommonTx
fn := func(c *mgo.Collection) error {
Expand All @@ -28,7 +28,7 @@ func TestIsContainVotingPeriodStartTag(t *testing.T) {
}

func TestHandleProposal(t *testing.T) {
txHash := "5875062EE8B8656CF943C42983F382B5341B1B0C530062D266BD8283CA9658B0"
txHash := "37A0127A87AA68BFE73D03C2B9A2A6A3D8E51DF242D86C845DB2D158B1617502"

var tx document.CommonTx
fn := func(c *mgo.Collection) error {
Expand Down
138 changes: 0 additions & 138 deletions service/handler/validator.go

This file was deleted.

61 changes: 0 additions & 61 deletions service/handler/validator_test.go

This file was deleted.

Loading

0 comments on commit 138a7d2

Please sign in to comment.