diff options
-rw-r--r-- | consensus/dexcon/dexcon.go | 13 | ||||
-rw-r--r-- | core/blockchain.go | 2 | ||||
-rw-r--r-- | core/governance.go | 5 | ||||
-rw-r--r-- | dex/app.go | 80 | ||||
-rw-r--r-- | dex/governance.go | 6 | ||||
-rw-r--r-- | dex/handler.go | 6 | ||||
-rw-r--r-- | params/config.go | 8 | ||||
-rw-r--r-- | vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go | 1 |
8 files changed, 35 insertions, 86 deletions
diff --git a/consensus/dexcon/dexcon.go b/consensus/dexcon/dexcon.go index 2e406f0b0..70ed4e141 100644 --- a/consensus/dexcon/dexcon.go +++ b/consensus/dexcon/dexcon.go @@ -113,17 +113,6 @@ func (d *Dexcon) calculateBlockReward(round int64, state *state.StateDB) *big.In gsCurrent := vm.GovernanceStateHelper{state} configCurrent := gsCurrent.Configuration() - heightCurrent := gsCurrent.RoundHeight(big.NewInt(round)).Uint64() - - blocksPerRound := uint64(0) - - // The initial round, calculate an approximate number of round base on config. - if round == 0 || heightCurrent == 0 { - blocksPerRound = uint64(config.NumChains) * config.RoundInterval / config.MinBlockInterval - } else { - heightPrev := gsCurrent.RoundHeight(big.NewInt(round - 1)).Uint64() - blocksPerRound = heightCurrent - heightPrev - } // blockReard = miningVelocity * totalStaked * roundInterval / aYear / numBlocksInPrevRound numerator, _ := new(big.Float).Mul( @@ -135,7 +124,7 @@ func (d *Dexcon) calculateBlockReward(round int64, state *state.StateDB) *big.In reward := new(big.Int).Div(numerator, new(big.Int).Mul( big.NewInt(86400*1000*365), - big.NewInt(int64(blocksPerRound)))) + big.NewInt(int64(config.RoundInterval)))) return reward } diff --git a/core/blockchain.go b/core/blockchain.go index 6307cc12f..42cd83267 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -293,7 +293,7 @@ type blockInfo struct { } func (bc *BlockChain) AddConfirmedBlock(block *coreTypes.Block) error { - chainID := block.Position.ChainID + chainID := uint32(0) bc.confirmedBlockInitMu.Lock() _, exist := bc.confirmedBlocks[chainID] if !exist { diff --git a/core/governance.go b/core/governance.go index 538cd2b96..a6c08a1d3 100644 --- a/core/governance.go +++ b/core/governance.go @@ -91,14 +91,11 @@ func (g *Governance) Configuration(round uint64) *coreTypes.Config { configHelper := g.GetGovStateHelperAtRound(round) c := configHelper.Configuration() return &coreTypes.Config{ - NumChains: c.NumChains, LambdaBA: time.Duration(c.LambdaBA) * time.Millisecond, LambdaDKG: time.Duration(c.LambdaDKG) * time.Millisecond, - K: int(c.K), - PhiRatio: c.PhiRatio, NotarySetSize: c.NotarySetSize, DKGSetSize: c.DKGSetSize, - RoundInterval: time.Duration(c.RoundInterval) * time.Millisecond, + RoundInterval: c.RoundInterval, MinBlockInterval: time.Duration(c.MinBlockInterval) * time.Millisecond, } } diff --git a/dex/app.go b/dex/app.go index 6739ebabb..0e71beda7 100644 --- a/dex/app.go +++ b/dex/app.go @@ -29,7 +29,6 @@ import ( "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/core" - "github.com/dexon-foundation/dexon/core/rawdb" "github.com/dexon-foundation/dexon/core/types" "github.com/dexon-foundation/dexon/ethdb" "github.com/dexon-foundation/dexon/event" @@ -166,34 +165,17 @@ func (d *DexconApp) PreparePayload(position coreTypes.Position) (payload []byte, func (d *DexconApp) preparePayload(ctx context.Context, position coreTypes.Position) ( payload []byte, err error) { - d.chainRLock(position.ChainID) - defer d.chainRUnlock(position.ChainID) + d.chainRLock(0) + defer d.chainRUnlock(0) select { // This case will hit if previous RLock took too much time. case <-ctx.Done(): return default: } - - if position.Round > 0 { - // If round chain number changed but new round is not delivered yet, payload must be nil. - previousNumChains := d.gov.Configuration(position.Round - 1).NumChains - currentNumChains := d.gov.Configuration(position.Round).NumChains - if previousNumChains != currentNumChains { - deliveredRound, err := rawdb.ReadLastRoundNumber(d.chainDB) - if err != nil { - panic(fmt.Errorf("read current round error: %v", err)) - } - - if deliveredRound < position.Round { - return nil, nil - } - } - } - if position.Height != 0 { // Check if chain block height is strictly increamental. - chainLastHeight, ok := d.blockchain.GetChainLastConfirmedHeight(position.ChainID) + chainLastHeight, ok := d.blockchain.GetChainLastConfirmedHeight(0) if !ok || chainLastHeight != position.Height-1 { log.Debug("Previous confirmed block not exists", "current pos", position.String(), "prev height", chainLastHeight, "ok", ok) @@ -201,7 +183,7 @@ func (d *DexconApp) preparePayload(ctx context.Context, position coreTypes.Posit } } - root, exist := d.chainRoot.Load(position.ChainID) + root, exist := d.chainRoot.Load(uint32(0)) if !exist { return nil, nil } @@ -210,15 +192,15 @@ func (d *DexconApp) preparePayload(ctx context.Context, position coreTypes.Posit if err != nil { return nil, err } - log.Debug("Prepare payload", "chain", position.ChainID, "height", position.Height) + log.Debug("Prepare payload", "chain", 0, "height", position.Height) txsMap, err := d.txPool.Pending() if err != nil { return } - chainID := new(big.Int).SetUint64(uint64(position.ChainID)) - chainNums := new(big.Int).SetUint64(uint64(d.gov.GetNumChains(position.Round))) + chainID := new(big.Int).SetUint64(uint64(0)) + chainNums := new(big.Int).SetUint64(uint64(1)) blockGasLimit := new(big.Int).SetUint64(d.gov.DexconConfiguration(position.Round).BlockGasLimit) blockGasUsed := new(big.Int) allTxs := make([]*types.Transaction, 0, 3000) @@ -236,13 +218,13 @@ addressMap: } balance := currentState.GetBalance(address) - cost, exist := d.blockchain.GetCostInConfirmedBlocks(position.ChainID, address) + cost, exist := d.blockchain.GetCostInConfirmedBlocks(0, address) if exist { balance = new(big.Int).Sub(balance, cost) } var expectNonce uint64 - lastConfirmedNonce, exist := d.blockchain.GetLastNonceInConfirmedBlocks(position.ChainID, address) + lastConfirmedNonce, exist := d.blockchain.GetLastNonceInConfirmedBlocks(0, address) if !exist { expectNonce = currentState.GetNonce(address) } else { @@ -342,13 +324,13 @@ func (d *DexconApp) VerifyBlock(block *coreTypes.Block) coreTypes.BlockVerifySta return coreTypes.VerifyInvalidBlock } - d.chainRLock(block.Position.ChainID) - defer d.chainRUnlock(block.Position.ChainID) + d.chainRLock(0) + defer d.chainRUnlock(0) if block.Position.Height != 0 { // Check if target block is the next height to be verified, we can only // verify the next block in a given chain. - chainLastHeight, ok := d.blockchain.GetChainLastConfirmedHeight(block.Position.ChainID) + chainLastHeight, ok := d.blockchain.GetChainLastConfirmedHeight(0) if !ok || chainLastHeight != block.Position.Height-1 { log.Debug("Previous confirmed block not exists", "current pos", block.Position.String(), "prev height", chainLastHeight, "ok", ok) @@ -356,34 +338,14 @@ func (d *DexconApp) VerifyBlock(block *coreTypes.Block) coreTypes.BlockVerifySta } } - if block.Position.Round > 0 { - // If round chain number changed but new round is not delivered yet, payload must be nil. - previousNumChains := d.gov.Configuration(block.Position.Round - 1).NumChains - currentNumChains := d.gov.Configuration(block.Position.Round).NumChains - if previousNumChains != currentNumChains { - deliveredRound, err := rawdb.ReadLastRoundNumber(d.chainDB) - if err != nil { - panic(fmt.Errorf("read current round error: %v", err)) - } - - if deliveredRound < block.Position.Round { - if len(block.Payload) > 0 { - return coreTypes.VerifyInvalidBlock - } - - return coreTypes.VerifyOK - } - } - } - // Get latest state with current chain. - root, exist := d.chainRoot.Load(block.Position.ChainID) + root, exist := d.chainRoot.Load(uint32(0)) if !exist { return coreTypes.VerifyRetryLater } currentState, err := d.blockchain.StateAt(*root.(*common.Hash)) - log.Debug("Verify block", "chain", block.Position.ChainID, "height", block.Position.Height) + log.Debug("Verify block", "chain", 0, "height", block.Position.Height) if err != nil { log.Debug("Invalid state root", "root", *root.(*common.Hash), "err", err) return coreTypes.VerifyInvalidBlock @@ -412,8 +374,8 @@ func (d *DexconApp) VerifyBlock(block *coreTypes.Block) coreTypes.BlockVerifySta } // Check if nonce is strictly increasing for every address. - chainID := big.NewInt(int64(block.Position.ChainID)) - chainNums := big.NewInt(int64(d.gov.GetNumChains(block.Position.Round))) + chainID := big.NewInt(int64(0)) + chainNums := big.NewInt(int64(1)) for address, firstNonce := range addressNonce { if !d.addrBelongsToChain(address, chainNums, chainID) { @@ -422,7 +384,7 @@ func (d *DexconApp) VerifyBlock(block *coreTypes.Block) coreTypes.BlockVerifySta } var expectNonce uint64 - lastConfirmedNonce, exist := d.blockchain.GetLastNonceInConfirmedBlocks(block.Position.ChainID, address) + lastConfirmedNonce, exist := d.blockchain.GetLastNonceInConfirmedBlocks(0, address) if exist { expectNonce = lastConfirmedNonce + 1 } else { @@ -438,7 +400,7 @@ func (d *DexconApp) VerifyBlock(block *coreTypes.Block) coreTypes.BlockVerifySta // Calculate balance in last state (including pending state). addressesBalance := map[common.Address]*big.Int{} for address := range addressNonce { - cost, exist := d.blockchain.GetCostInConfirmedBlocks(block.Position.ChainID, address) + cost, exist := d.blockchain.GetCostInConfirmedBlocks(0, address) if exist { addressesBalance[address] = new(big.Int).Sub(currentState.GetBalance(address), cost) } else { @@ -493,7 +455,7 @@ func (d *DexconApp) BlockDelivered( log.Debug("DexconApp block deliver", "height", result.Height, "hash", blockHash, "position", blockPosition.String()) defer log.Debug("DexconApp block delivered", "height", result.Height, "hash", blockHash, "position", blockPosition.String()) - chainID := blockPosition.ChainID + chainID := uint32(0) d.chainLock(chainID) defer d.chainUnlock(chainID) @@ -551,8 +513,8 @@ func (d *DexconApp) BlockDelivered( // BlockConfirmed is called when a block is confirmed and added to lattice. func (d *DexconApp) BlockConfirmed(block coreTypes.Block) { - d.chainLock(block.Position.ChainID) - defer d.chainUnlock(block.Position.ChainID) + d.chainLock(0) + defer d.chainUnlock(0) log.Debug("DexconApp block confirmed", "block", block.String()) if err := d.blockchain.AddConfirmedBlock(&block); err != nil { diff --git a/dex/governance.go b/dex/governance.go index 1b037cf2b..c6e284e80 100644 --- a/dex/governance.go +++ b/dex/governance.go @@ -230,11 +230,11 @@ func (d *DexconGovernance) ReportForkBlock(block1, block2 *coreTypes.Block) { } func (d *DexconGovernance) GetNumChains(round uint64) uint32 { - return d.Configuration(round).NumChains + return 1 } -func (d *DexconGovernance) NotarySet(round uint64, chainID uint32) (map[string]struct{}, error) { - notarySet, err := d.nodeSetCache.GetNotarySet(round, chainID) +func (d *DexconGovernance) NotarySet(round uint64, _ uint32) (map[string]struct{}, error) { + notarySet, err := d.nodeSetCache.GetNotarySet(round) if err != nil { return nil, err } diff --git a/dex/handler.go b/dex/handler.go index 309a6a33e..dee6df7ac 100644 --- a/dex/handler.go +++ b/dex/handler.go @@ -1011,7 +1011,7 @@ func (pm *ProtocolManager) BroadcastVote(vote *coreTypes.Vote) { } label := peerLabel{ set: notaryset, - chainID: vote.Position.ChainID, + chainID: 0, round: vote.Position.Round, } for _, peer := range pm.peers.PeersWithLabel(label) { @@ -1044,7 +1044,7 @@ func (pm *ProtocolManager) BroadcastRandomnessResult( // send to notary nodes first (direct) label := peerLabel{ set: notaryset, - chainID: randomness.Position.ChainID, + chainID: 0, round: randomness.Position.Round, } randomnesses := []*coreTypes.BlockRandomnessResult{randomness} @@ -1110,7 +1110,7 @@ func (pm *ProtocolManager) BroadcastPullVotes( pos coreTypes.Position) { label := peerLabel{ set: notaryset, - chainID: pos.ChainID, + chainID: 0, round: pos.Round, } for idx, peer := range pm.peers.PeersWithLabel(label) { diff --git a/params/config.go b/params/config.go index 886f8f1e3..48bd6a7ba 100644 --- a/params/config.go +++ b/params/config.go @@ -60,7 +60,7 @@ var ( PhiRatio: 0.667, NotarySetSize: 4, DKGSetSize: 4, - RoundInterval: 600000, + RoundInterval: 150, MinBlockInterval: 1000, FineValues: []*big.Int{ new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e4)), @@ -107,7 +107,7 @@ var ( PhiRatio: 0.667, NotarySetSize: 4, DKGSetSize: 4, - RoundInterval: 1200000, + RoundInterval: 150, MinBlockInterval: 1000, FineValues: []*big.Int{ new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e4)), @@ -120,7 +120,7 @@ var ( // TaipeiChainConfig contains the chain parameters to run a node on the Taipei test network. TaipeiChainConfig = &ChainConfig{ ChainID: big.NewInt(239), - DMoment: 1548556500, + DMoment: 1550645400, HomesteadBlock: big.NewInt(0), DAOForkBlock: nil, DAOForkSupport: true, @@ -145,7 +145,7 @@ var ( PhiRatio: 0.667, NotarySetSize: 21, DKGSetSize: 13, - RoundInterval: 1800000, + RoundInterval: 150, MinBlockInterval: 1000, FineValues: []*big.Int{ new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e4)), 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 88cc432ff..19dbb55ea 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 @@ -201,6 +201,7 @@ func (mgr *agreementMgr) appendConfig( } func (mgr *agreementMgr) processVote(v *types.Vote) (err error) { + mgr.logger.Debug("processVote", "ID", mgr.ID.String()[:6], "vote", v) if mgr.voteFilter.Filter(v) { return nil } |