diff options
author | Wei-Ning Huang <w@dexon.org> | 2019-04-17 13:46:33 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-15 22:09:56 +0800 |
commit | a3b419d3b0d72dd7624bcf921296fa83db921bbf (patch) | |
tree | a507cd8d91c33260618a73f815c2d54426cb82b8 | |
parent | e5a19c746a9ebf7c95ee0d506a1a8a8dc05c1db5 (diff) | |
download | go-tangerine-a3b419d3b0d72dd7624bcf921296fa83db921bbf.tar.gz go-tangerine-a3b419d3b0d72dd7624bcf921296fa83db921bbf.tar.zst go-tangerine-a3b419d3b0d72dd7624bcf921296fa83db921bbf.zip |
core: vm: refine panic flow (#372)
Move panic call to immediate location of the error to prevent
accidententaly panic on other conditions.
-rw-r--r-- | core/vm/oracle_contracts.go | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/core/vm/oracle_contracts.go b/core/vm/oracle_contracts.go index 4a93c9805..b47f99ee0 100644 --- a/core/vm/oracle_contracts.go +++ b/core/vm/oracle_contracts.go @@ -528,23 +528,21 @@ func (s *GovernanceState) DeleteNodesOffsetByNodeKeyAddress(addr common.Address) s.setStateBigInt(loc, big.NewInt(0)) } -func (s *GovernanceState) PutNodeOffsets(n *nodeInfo, offset *big.Int) error { +func (s *GovernanceState) PutNodeOffsets(n *nodeInfo, offset *big.Int) { address, err := publicKeyToNodeKeyAddress(n.PublicKey) if err != nil { - return err + panic(err) } s.PutNodesOffsetByNodeKeyAddress(address, offset) s.PutNodesOffsetByAddress(n.Owner, offset) - return nil } -func (s *GovernanceState) DeleteNodeOffsets(n *nodeInfo) error { +func (s *GovernanceState) DeleteNodeOffsets(n *nodeInfo) { address, err := publicKeyToNodeKeyAddress(n.PublicKey) if err != nil { - return err + panic(err) } s.DeleteNodesOffsetByNodeKeyAddress(address) s.DeleteNodesOffsetByAddress(n.Owner) - return nil } func (s *GovernanceState) GetNodeByID(id coreTypes.NodeID) (*nodeInfo, error) { @@ -990,9 +988,7 @@ func (s *GovernanceState) Register( UnstakedAt: big.NewInt(0), } s.PushNode(node) - if err := s.PutNodeOffsets(node, offset); err != nil { - panic(err) - } + s.PutNodeOffsets(node, offset) if staked.Cmp(big.NewInt(0)) == 0 { return @@ -1759,9 +1755,7 @@ func (g *GovernanceContract) register( UnstakedAt: big.NewInt(0), } g.state.PushNode(node) - if err := g.state.PutNodeOffsets(node, offset); err != nil { - return nil, errExecutionReverted - } + g.state.PutNodeOffsets(node, offset) g.state.emitNodeAdded(caller) if value.Cmp(big.NewInt(0)) > 0 { @@ -1870,9 +1864,7 @@ func (g *GovernanceContract) withdraw() ([]byte, error) { if offset.Cmp(lastIndex) != 0 { lastNode := g.state.Node(lastIndex) g.state.UpdateNode(offset, lastNode) - if err := g.state.PutNodeOffsets(lastNode, offset); err != nil { - panic(err) - } + g.state.PutNodeOffsets(lastNode, offset) } g.state.DeleteNodeOffsets(node) g.state.PopLastNode() |