diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-01-27 10:10:11 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-03-12 12:19:09 +0800 |
commit | ed7c9498b1d93d284da44ab5171c5ed741845aa8 (patch) | |
tree | 42fac2c65c7821d9ff99880707e4c943a7e6fb43 | |
parent | ae0afc07282e21345904f1a2177eff24d2594429 (diff) | |
download | dexon-ed7c9498b1d93d284da44ab5171c5ed741845aa8.tar.gz dexon-ed7c9498b1d93d284da44ab5171c5ed741845aa8.tar.zst dexon-ed7c9498b1d93d284da44ab5171c5ed741845aa8.zip |
params: update testnet config (#177)
* vendor:sync to latest core
* params: Update config for testnet
-rw-r--r-- | params/config.go | 6 | ||||
-rw-r--r-- | vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go | 89 | ||||
-rw-r--r-- | vendor/github.com/dexon-foundation/dexon-consensus/core/compaction-chain.go | 48 | ||||
-rw-r--r-- | vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go | 75 | ||||
-rw-r--r-- | vendor/vendor.json | 42 |
5 files changed, 164 insertions, 96 deletions
diff --git a/params/config.go b/params/config.go index b9b3fbd6d..dec0a7b5f 100644 --- a/params/config.go +++ b/params/config.go @@ -27,7 +27,7 @@ import ( // Genesis hashes to enforce below configs on. var ( MainnetGenesisHash = common.HexToHash("0xe972af2797b02f4dab95ffa229714c35d5c55685f20261b9498c8b8a3fe33856") - TestnetGenesisHash = common.HexToHash("0xd38d11902c6e134bb85112c05a8faa92ae5189474591ac1343e849be29d7d643") + TestnetGenesisHash = common.HexToHash("0xaf79c06141610103c4728d4e7da2effcc7ee568af46a8cb5c13082315d597d73") ) var ( @@ -83,7 +83,7 @@ var ( // TestnetChainConfig contains the chain parameters to run a node on the Taiwan test network. TestnetChainConfig = &ChainConfig{ ChainID: big.NewInt(238), - DMoment: 1548249900, + DMoment: 1548504300, HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, DAOForkSupport: true, @@ -102,7 +102,7 @@ var ( NextHalvingSupply: new(big.Int).Mul(big.NewInt(1e18), big.NewInt(2e7)), LastHalvedAmount: new(big.Int).Mul(big.NewInt(1e18), big.NewInt(4e6)), BlockGasLimit: 40000000, - NumChains: 6, + NumChains: 4, LambdaBA: 250, LambdaDKG: 4000, K: 0, diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go index a8fab7c69..bcf10139c 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go @@ -35,6 +35,8 @@ var ( ErrPreviousRoundIsNotFinished = errors.New("previous round is not finished") ) +const maxResultCache = 100 + // genValidLeader generate a validLeader function for agreement modules. func genValidLeader( mgr *agreementMgr) func(*types.Block) (bool, error) { @@ -80,25 +82,26 @@ type baRoundSetting struct { type agreementMgr struct { // TODO(mission): unbound Consensus instance from this module. - con *Consensus - ID types.NodeID - app Application - gov Governance - network Network - logger common.Logger - cache *utils.NodeSetCache - signer *utils.Signer - lattice *Lattice - ctx context.Context - lastEndTime time.Time - initRound uint64 - configs []*agreementMgrConfig - baModules []*agreement - voteFilters []*utils.VoteFilter - waitGroup sync.WaitGroup - pendingVotes map[uint64][]*types.Vote - pendingBlocks map[uint64][]*types.Block - isRunning bool + con *Consensus + ID types.NodeID + app Application + gov Governance + network Network + logger common.Logger + cache *utils.NodeSetCache + signer *utils.Signer + lattice *Lattice + ctx context.Context + lastEndTime time.Time + initRound uint64 + configs []*agreementMgrConfig + baModules []*agreement + processedBAResult map[types.Position]struct{} + voteFilters []*utils.VoteFilter + waitGroup sync.WaitGroup + pendingVotes map[uint64][]*types.Vote + pendingBlocks map[uint64][]*types.Block + isRunning bool // This lock should be used when attempting to: // - add a new baModule. @@ -114,18 +117,19 @@ type agreementMgr struct { func newAgreementMgr(con *Consensus, initRound uint64, initRoundBeginTime time.Time) *agreementMgr { return &agreementMgr{ - con: con, - ID: con.ID, - app: con.app, - gov: con.gov, - network: con.network, - logger: con.logger, - cache: con.nodeSetCache, - signer: con.signer, - lattice: con.lattice, - ctx: con.ctx, - initRound: initRound, - lastEndTime: initRoundBeginTime, + con: con, + ID: con.ID, + app: con.app, + gov: con.gov, + network: con.network, + logger: con.logger, + cache: con.nodeSetCache, + signer: con.signer, + lattice: con.lattice, + ctx: con.ctx, + initRound: initRound, + lastEndTime: initRoundBeginTime, + processedBAResult: make(map[types.Position]struct{}, maxResultCache), } } @@ -251,6 +255,29 @@ func (mgr *agreementMgr) processBlock(b *types.Block) error { return mgr.baModules[b.Position.ChainID].processBlock(b) } +func (mgr *agreementMgr) touchAgreementResult( + result *types.AgreementResult) (first bool) { + // DO NOT LOCK THIS FUNCTION!!!!!!!! YOU WILL REGRET IT!!!!! + if _, exist := mgr.processedBAResult[result.Position]; !exist { + first = true + if len(mgr.processedBAResult) > maxResultCache { + for k := range mgr.processedBAResult { + // Randomly drop one element. + delete(mgr.processedBAResult, k) + break + } + } + mgr.processedBAResult[result.Position] = struct{}{} + } + return +} + +func (mgr *agreementMgr) untouchAgreementResult( + result *types.AgreementResult) { + // DO NOT LOCK THIS FUNCTION!!!!!!!! YOU WILL REGRET IT!!!!! + delete(mgr.processedBAResult, result.Position) +} + func (mgr *agreementMgr) processAgreementResult( result *types.AgreementResult) error { mgr.lock.RLock() diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/compaction-chain.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/compaction-chain.go index 8e044293f..d7c2f8556 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/compaction-chain.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/compaction-chain.go @@ -41,6 +41,7 @@ var ( ) const maxPendingPeriod = 3 * time.Second +const maxRandomnessCache = 100 type pendingRandomnessResult struct { receivedTime time.Time @@ -50,24 +51,26 @@ type pendingRandomnessResult struct { type finalizedBlockHeap = types.ByFinalizationHeight type compactionChain struct { - gov Governance - chainUnsynced uint32 - tsigVerifier *TSigVerifierCache - blocks map[common.Hash]*types.Block - blockRandomness map[common.Hash][]byte - pendingRandomness map[common.Hash]pendingRandomnessResult - pendingBlocks []*types.Block - lock sync.RWMutex - prevBlock *types.Block + gov Governance + chainUnsynced uint32 + tsigVerifier *TSigVerifierCache + blocks map[common.Hash]*types.Block + blockRandomness map[common.Hash][]byte + pendingRandomness map[common.Hash]pendingRandomnessResult + processedRandomnessResult map[types.Position]struct{} + pendingBlocks []*types.Block + lock sync.RWMutex + prevBlock *types.Block } func newCompactionChain(gov Governance) *compactionChain { return &compactionChain{ - gov: gov, - tsigVerifier: NewTSigVerifierCache(gov, 7), - blocks: make(map[common.Hash]*types.Block), - blockRandomness: make(map[common.Hash][]byte), - pendingRandomness: make(map[common.Hash]pendingRandomnessResult), + gov: gov, + tsigVerifier: NewTSigVerifierCache(gov, 7), + blocks: make(map[common.Hash]*types.Block), + blockRandomness: make(map[common.Hash][]byte), + pendingRandomness: make(map[common.Hash]pendingRandomnessResult), + processedRandomnessResult: make(map[types.Position]struct{}, maxRandomnessCache), } } @@ -207,6 +210,23 @@ func (cc *compactionChain) processFinalizedBlock(block *types.Block) error { return nil } +func (cc *compactionChain) touchBlockRandomnessResult( + rand *types.BlockRandomnessResult) (first bool) { + // DO NOT LOCK THIS FUNCTION!!!!!!!! YOU WILL REGRET IT!!!!! + if _, exist := cc.processedRandomnessResult[rand.Position]; !exist { + first = true + if len(cc.processedRandomnessResult) > maxRandomnessCache { + for k := range cc.processedRandomnessResult { + // Randomly drop one element. + delete(cc.processedRandomnessResult, k) + break + } + } + cc.processedRandomnessResult[rand.Position] = struct{}{} + } + return +} + func (cc *compactionChain) processBlockRandomnessResult( rand *types.BlockRandomnessResult) error { ok, err := cc.verifyRandomness( diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go index 3a27b5fc1..f46501038 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go @@ -1021,11 +1021,17 @@ func (con *Consensus) ProcessVote(vote *types.Vote) (err error) { // ProcessAgreementResult processes the randomness request. func (con *Consensus) ProcessAgreementResult( rand *types.AgreementResult) error { + if !con.baMgr.touchAgreementResult(rand) { + return nil + } + // Sanity Check. if err := VerifyAgreementResult(rand, con.nodeSetCache); err != nil { + con.baMgr.untouchAgreementResult(rand) return err } con.lattice.AddShallowBlock(rand.BlockHash, rand.Position) + // Syncing BA Module. if err := con.baMgr.processAgreementResult(rand); err != nil { return err @@ -1039,32 +1045,46 @@ func (con *Consensus) ProcessAgreementResult( if !con.cfgModule.touchTSigHash(rand.BlockHash) { return nil } + con.logger.Debug("Rebroadcast AgreementResult", "result", rand) con.network.BroadcastAgreementResult(rand) - dkgSet, err := con.nodeSetCache.GetDKGSet(rand.Position.Round) - if err != nil { - return err - } - if _, exist := dkgSet[con.ID]; !exist { - return nil - } - psig, err := con.cfgModule.preparePartialSignature(rand.Position.Round, rand.BlockHash) - if err != nil { - return err - } - if err = con.signer.SignDKGPartialSignature(psig); err != nil { - return err - } - if err = con.cfgModule.processPartialSignature(psig); err != nil { - return err - } - con.logger.Debug("Calling Network.BroadcastDKGPartialSignature", - "proposer", psig.ProposerID, - "round", psig.Round, - "hash", psig.Hash.String()[:6]) - con.network.BroadcastDKGPartialSignature(psig) + go func() { + dkgSet, err := con.nodeSetCache.GetDKGSet(rand.Position.Round) + if err != nil { + con.logger.Error("Failed to get dkg set", + "round", rand.Position.Round, "error", err) + return + } + if _, exist := dkgSet[con.ID]; !exist { + return + } + psig, err := con.cfgModule.preparePartialSignature(rand.Position.Round, rand.BlockHash) + if err != nil { + con.logger.Error("Failed to prepare psig", + "round", rand.Position.Round, + "hash", rand.BlockHash.String()[:6], + "error", err) + return + } + if err = con.signer.SignDKGPartialSignature(psig); err != nil { + con.logger.Error("Failed to sign psig", + "hash", rand.BlockHash.String()[:6], + "error", err) + return + } + if err = con.cfgModule.processPartialSignature(psig); err != nil { + con.logger.Error("Failed process psig", + "hash", rand.BlockHash.String()[:6], + "error", err) + return + } + con.logger.Debug("Calling Network.BroadcastDKGPartialSignature", + "proposer", psig.ProposerID, + "round", psig.Round, + "hash", psig.Hash.String()[:6]) + con.network.BroadcastDKGPartialSignature(psig) tsig, err := con.cfgModule.runTSig(rand.Position.Round, rand.BlockHash) if err != nil { if err != ErrTSigAlreadyRunning { @@ -1080,11 +1100,9 @@ func (con *Consensus) ProcessAgreementResult( Position: rand.Position, Randomness: tsig.Signature, } - if err := con.ProcessBlockRandomnessResult(result, true); err != nil { - con.logger.Error("Failed to process randomness result", - "error", err) - return - } + // ProcessBlockRandomnessResult is not thread-safe so we put the result in + // the message channnel to be processed in the main thread. + con.msgChan <- result }() return nil } @@ -1095,6 +1113,9 @@ func (con *Consensus) ProcessBlockRandomnessResult( if rand.Position.Round == 0 { return nil } + if !con.ccModule.touchBlockRandomnessResult(rand) { + return nil + } if err := con.ccModule.processBlockRandomnessResult(rand); err != nil { if err == ErrBlockNotRegistered { err = nil diff --git a/vendor/vendor.json b/vendor/vendor.json index 8e24d3b94..74b0eb0ba 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -141,16 +141,16 @@ { "checksumSHA1": "MA1hygDGoOGggSd39fadmgoK0u0=", "path": "github.com/dexon-foundation/dexon-consensus/common", - "revision": "b6ca251bcb6e1a19a7276afe68bf37a4372670fa", - "revisionTime": "2019-01-24T03:49:25Z", + "revision": "049c9820e803f0453442d858d2ef36219981bf4c", + "revisionTime": "2019-01-26T07:33:24Z", "version": "master", "versionExact": "master" }, { - "checksumSHA1": "HadLM8+Kxjh0S0tPufyHqjMHquw=", + "checksumSHA1": "KPajxfz3zYL+BqTkiPI+4qShEP4=", "path": "github.com/dexon-foundation/dexon-consensus/core", - "revision": "b6ca251bcb6e1a19a7276afe68bf37a4372670fa", - "revisionTime": "2019-01-24T03:49:25Z", + "revision": "049c9820e803f0453442d858d2ef36219981bf4c", + "revisionTime": "2019-01-26T07:33:24Z", "version": "master", "versionExact": "master" }, @@ -165,64 +165,64 @@ { "checksumSHA1": "tQSbYCu5P00lUhKsx3IbBZCuSLY=", "path": "github.com/dexon-foundation/dexon-consensus/core/crypto", - "revision": "b6ca251bcb6e1a19a7276afe68bf37a4372670fa", - "revisionTime": "2019-01-24T03:49:25Z", + "revision": "049c9820e803f0453442d858d2ef36219981bf4c", + "revisionTime": "2019-01-26T07:33:24Z", "version": "master", "versionExact": "master" }, { "checksumSHA1": "Nlv7pi1DIBftY+r6CFP8LBIQA3U=", "path": "github.com/dexon-foundation/dexon-consensus/core/crypto/dkg", - "revision": "b6ca251bcb6e1a19a7276afe68bf37a4372670fa", - "revisionTime": "2019-01-24T03:49:25Z", + "revision": "049c9820e803f0453442d858d2ef36219981bf4c", + "revisionTime": "2019-01-26T07:33:24Z", "version": "master", "versionExact": "master" }, { "checksumSHA1": "BhLKK8RveoLaeXc9UyUKMwQqchU=", "path": "github.com/dexon-foundation/dexon-consensus/core/crypto/ecdsa", - "revision": "b6ca251bcb6e1a19a7276afe68bf37a4372670fa", - "revisionTime": "2019-01-24T03:49:25Z", + "revision": "049c9820e803f0453442d858d2ef36219981bf4c", + "revisionTime": "2019-01-26T07:33:24Z", "version": "master", "versionExact": "master" }, { "checksumSHA1": "zpuCdMT8MGsy4pLgHKpg/Wd4izU=", "path": "github.com/dexon-foundation/dexon-consensus/core/db", - "revision": "b6ca251bcb6e1a19a7276afe68bf37a4372670fa", - "revisionTime": "2019-01-24T03:49:25Z", + "revision": "049c9820e803f0453442d858d2ef36219981bf4c", + "revisionTime": "2019-01-26T07:33:24Z", "version": "master", "versionExact": "master" }, { "checksumSHA1": "eq19vhMpc90UUJ7I91ti5P2CkQ0=", "path": "github.com/dexon-foundation/dexon-consensus/core/syncer", - "revision": "b6ca251bcb6e1a19a7276afe68bf37a4372670fa", - "revisionTime": "2019-01-24T03:49:25Z", + "revision": "049c9820e803f0453442d858d2ef36219981bf4c", + "revisionTime": "2019-01-26T07:33:24Z", "version": "master", "versionExact": "master" }, { "checksumSHA1": "OOyjMSUDuT8n/IJLFpDxENpgf/A=", "path": "github.com/dexon-foundation/dexon-consensus/core/types", - "revision": "b6ca251bcb6e1a19a7276afe68bf37a4372670fa", - "revisionTime": "2019-01-24T03:49:25Z", + "revision": "049c9820e803f0453442d858d2ef36219981bf4c", + "revisionTime": "2019-01-26T07:33:24Z", "version": "master", "versionExact": "master" }, { "checksumSHA1": "rmv8uxwrqMhJAeA3RPvwYP8mFro=", "path": "github.com/dexon-foundation/dexon-consensus/core/types/dkg", - "revision": "b6ca251bcb6e1a19a7276afe68bf37a4372670fa", - "revisionTime": "2019-01-24T03:49:25Z", + "revision": "049c9820e803f0453442d858d2ef36219981bf4c", + "revisionTime": "2019-01-26T07:33:24Z", "version": "master", "versionExact": "master" }, { "checksumSHA1": "ZRpjtBZT6CEIqysdaONmteBCy4A=", "path": "github.com/dexon-foundation/dexon-consensus/core/utils", - "revision": "b6ca251bcb6e1a19a7276afe68bf37a4372670fa", - "revisionTime": "2019-01-24T03:49:25Z", + "revision": "049c9820e803f0453442d858d2ef36219981bf4c", + "revisionTime": "2019-01-26T07:33:24Z", "version": "master", "versionExact": "master" }, |