diff options
author | Wei-Ning Huang <w@dexon.org> | 2019-01-24 15:05:24 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-03-12 12:19:09 +0800 |
commit | 6c3d02b7c43ee470938fb929f60336d151cf25ca (patch) | |
tree | 842113610aae4631622cc1052d7d00e8befc9d8b /core | |
parent | df60600936084e5c0b795c1a53dd65fa778b37be (diff) | |
download | dexon-6c3d02b7c43ee470938fb929f60336d151cf25ca.tar dexon-6c3d02b7c43ee470938fb929f60336d151cf25ca.tar.gz dexon-6c3d02b7c43ee470938fb929f60336d151cf25ca.tar.bz2 dexon-6c3d02b7c43ee470938fb929f60336d151cf25ca.tar.lz dexon-6c3d02b7c43ee470938fb929f60336d151cf25ca.tar.xz dexon-6c3d02b7c43ee470938fb929f60336d151cf25ca.tar.zst dexon-6c3d02b7c43ee470938fb929f60336d151cf25ca.zip |
consensus: dexcon: snapshot round height when finalizing block (#170)
Instead of having BP to send a tx to register the round height, just
modify the state when finalizing block.
Diffstat (limited to 'core')
-rw-r--r-- | core/vm/governance.go | 48 | ||||
-rw-r--r-- | core/vm/governance_abi.go | 18 | ||||
-rw-r--r-- | core/vm/governance_test.go | 40 |
3 files changed, 0 insertions, 106 deletions
diff --git a/core/vm/governance.go b/core/vm/governance.go index a0014005d..b400ba61b 100644 --- a/core/vm/governance.go +++ b/core/vm/governance.go @@ -196,15 +196,6 @@ func RunGovernanceContract(evm *EVM, input []byte, contract *Contract) (ret []by return nil, errExecutionReverted } return g.stake(args.PublicKey, args.Name, args.Email, args.Location, args.Url) - case "snapshotRound": - args := struct { - Round *big.Int - Height *big.Int - }{} - if err := method.Inputs.Unpack(&args, arguments); err != nil { - return nil, errExecutionReverted - } - return g.snapshotRound(args.Round, args.Height) case "transferOwnership": var newOwner common.Address if err := method.Inputs.Unpack(&newOwner, arguments); err != nil { @@ -711,9 +702,6 @@ func (s *GovernanceStateHelper) appendTo2DByteArray(pos, index *big.Int, data [] } // uint256[] public roundHeight; -func (s *GovernanceStateHelper) LenRoundHeight() *big.Int { - return s.getStateBigInt(big.NewInt(roundHeightLoc)) -} func (s *GovernanceStateHelper) RoundHeight(round *big.Int) *big.Int { baseLoc := s.getSlotLoc(big.NewInt(roundHeightLoc)) loc := new(big.Int).Add(baseLoc, round) @@ -2169,31 +2157,6 @@ func (g *GovernanceContract) transferOwnership(newOwner common.Address) ([]byte, return nil, nil } -func (g *GovernanceContract) snapshotRound(round, height *big.Int) ([]byte, error) { - // Validate if this mapping is correct. Only block proposer need to verify this. - if g.evm.IsBlockProposer() { - realHeight, ok := g.evm.GetRoundHeight(round.Uint64()) - if !ok { - return g.penalize() - } - - if height.Cmp(new(big.Int).SetUint64(realHeight)) != 0 { - return g.penalize() - } - } - - // Only allow updating the next round. - nextRound := g.state.LenRoundHeight() - if round.Cmp(nextRound) != 0 { - // No need to penalize, since the only possibility at this point is the - // round height is already snapshoted. - return nil, errExecutionReverted - } - - g.state.PushRoundHeight(height) - return nil, nil -} - func PackProposeCRS(round uint64, signedCRS []byte) ([]byte, error) { method := GovernanceContractName2Method["proposeCRS"] res, err := method.Inputs.Pack(big.NewInt(int64(round)), signedCRS) @@ -2204,17 +2167,6 @@ func PackProposeCRS(round uint64, signedCRS []byte) ([]byte, error) { return data, nil } -func PackNotifyRoundHeight(targetRound, consensusHeight uint64) ([]byte, error) { - method := GovernanceContractName2Method["snapshotRound"] - res, err := method.Inputs.Pack( - big.NewInt(int64(targetRound)), big.NewInt(int64(consensusHeight))) - if err != nil { - return nil, err - } - data := append(method.Id(), res...) - return data, nil -} - func PackAddDKGMasterPublicKey(round uint64, mpk *dkgTypes.MasterPublicKey) ([]byte, error) { method := GovernanceContractName2Method["addDKGMasterPublicKey"] encoded, err := rlp.EncodeToBytes(mpk) diff --git a/core/vm/governance_abi.go b/core/vm/governance_abi.go index f139ac7a8..4627050dc 100644 --- a/core/vm/governance_abi.go +++ b/core/vm/governance_abi.go @@ -900,24 +900,6 @@ const GovernanceABIJSON = ` "type": "uint256" }, { - "name": "Height", - "type": "uint256" - } - ], - "name": "snapshotRound", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "Round", - "type": "uint256" - }, - { "name": "SignedCRS", "type": "bytes" } diff --git a/core/vm/governance_test.go b/core/vm/governance_test.go index 879bb406e..292e4ef1d 100644 --- a/core/vm/governance_test.go +++ b/core/vm/governance_test.go @@ -625,46 +625,6 @@ func (g *GovernanceContractTestSuite) TestUpdateConfiguration() { g.Require().NoError(err) } -func (g *GovernanceContractTestSuite) TestSnapshotRound() { - _, addr := g.newPrefundAccount() - - // Wrong height. - input, err := abiObject.Pack("snapshotRound", big.NewInt(1), big.NewInt(666)) - g.Require().NoError(err) - _, err = g.call(addr, input, big.NewInt(0)) - g.Require().NotNil(err) - - // Invalid round. - input, err = abiObject.Pack("snapshotRound", big.NewInt(2), big.NewInt(2000)) - g.Require().NoError(err) - _, err = g.call(addr, input, big.NewInt(0)) - g.Require().NotNil(err) - - // Correct. - input, err = abiObject.Pack("snapshotRound", big.NewInt(1), big.NewInt(1000)) - g.Require().NoError(err) - _, err = g.call(addr, input, big.NewInt(0)) - g.Require().NoError(err) - - // Duplicate round. - input, err = abiObject.Pack("snapshotRound", big.NewInt(1), big.NewInt(1000)) - g.Require().NoError(err) - _, err = g.call(addr, input, big.NewInt(0)) - g.Require().NotNil(err) - - // Invalid round. - input, err = abiObject.Pack("snapshotRound", big.NewInt(3), big.NewInt(3000)) - g.Require().NoError(err) - _, err = g.call(addr, input, big.NewInt(0)) - g.Require().NotNil(err) - - // Correct. - input, err = abiObject.Pack("snapshotRound", big.NewInt(2), big.NewInt(2000)) - g.Require().NoError(err) - _, err = g.call(addr, input, big.NewInt(0)) - g.Require().NoError(err) -} - func (g *GovernanceContractTestSuite) TestConfigurationReading() { _, addr := g.newPrefundAccount() |