diff options
Diffstat (limited to 'dex')
-rw-r--r-- | dex/app.go | 80 | ||||
-rw-r--r-- | dex/governance.go | 6 | ||||
-rw-r--r-- | dex/handler.go | 6 |
3 files changed, 27 insertions, 65 deletions
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) { |