aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2019-01-24 15:05:24 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 21:32:56 +0800
commit87db7f44d06ff4610b7a7a0b3bc845b8d8e342d0 (patch)
tree7243672ff3235c5fc741b09e0cadf7c69a7c6ec8 /core/vm
parent6f9f78e54ceb93db5495a3e15568efbfa9e5b25b (diff)
downloaddexon-87db7f44d06ff4610b7a7a0b3bc845b8d8e342d0.tar
dexon-87db7f44d06ff4610b7a7a0b3bc845b8d8e342d0.tar.gz
dexon-87db7f44d06ff4610b7a7a0b3bc845b8d8e342d0.tar.bz2
dexon-87db7f44d06ff4610b7a7a0b3bc845b8d8e342d0.tar.lz
dexon-87db7f44d06ff4610b7a7a0b3bc845b8d8e342d0.tar.xz
dexon-87db7f44d06ff4610b7a7a0b3bc845b8d8e342d0.tar.zst
dexon-87db7f44d06ff4610b7a7a0b3bc845b8d8e342d0.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.go48
-rw-r--r--core/vm/governance_abi.go18
-rw-r--r--core/vm/governance_test.go40
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()