diff options
author | Wei-Ning Huang <w@dexon.org> | 2019-01-24 15:05:24 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-24 15:05:24 +0800 |
commit | c7dd1a1b622eba3e28944f9d00827b7c5fe57c4a (patch) | |
tree | 846a0f56def1c9ce7855bc51a42d724192ecf7b7 /core/vm | |
parent | d60075505d75de052905caad3562ead280d83199 (diff) | |
download | dexon-c7dd1a1b622eba3e28944f9d00827b7c5fe57c4a.tar dexon-c7dd1a1b622eba3e28944f9d00827b7c5fe57c4a.tar.gz dexon-c7dd1a1b622eba3e28944f9d00827b7c5fe57c4a.tar.bz2 dexon-c7dd1a1b622eba3e28944f9d00827b7c5fe57c4a.tar.lz dexon-c7dd1a1b622eba3e28944f9d00827b7c5fe57c4a.tar.xz dexon-c7dd1a1b622eba3e28944f9d00827b7c5fe57c4a.tar.zst dexon-c7dd1a1b622eba3e28944f9d00827b7c5fe57c4a.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/vm')
-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 1022d77b4..8935356fb 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) @@ -2171,31 +2159,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) @@ -2206,17 +2169,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 0e66e113a..e42f2cad7 100644 --- a/core/vm/governance_abi.go +++ b/core/vm/governance_abi.go @@ -912,24 +912,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 b1dedc315..4847a919f 100644 --- a/core/vm/governance_test.go +++ b/core/vm/governance_test.go @@ -628,46 +628,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() |