aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2019-04-17 13:46:33 +0800
committerGitHub <noreply@github.com>2019-04-17 13:46:33 +0800
commitef3c55d921c37cccc6f6fe3fbf6e17be2d383903 (patch)
tree1fbccd1fab603965cfdc4873bd127df23e89b416
parent870509061af446bfc729924a611d6838d4cf8c17 (diff)
downloaddexon-ef3c55d921c37cccc6f6fe3fbf6e17be2d383903.tar
dexon-ef3c55d921c37cccc6f6fe3fbf6e17be2d383903.tar.gz
dexon-ef3c55d921c37cccc6f6fe3fbf6e17be2d383903.tar.bz2
dexon-ef3c55d921c37cccc6f6fe3fbf6e17be2d383903.tar.lz
dexon-ef3c55d921c37cccc6f6fe3fbf6e17be2d383903.tar.xz
dexon-ef3c55d921c37cccc6f6fe3fbf6e17be2d383903.tar.zst
dexon-ef3c55d921c37cccc6f6fe3fbf6e17be2d383903.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.go22
1 files changed, 7 insertions, 15 deletions
diff --git a/core/vm/oracle_contracts.go b/core/vm/oracle_contracts.go
index 2d4f27e99..40ea86ac9 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
@@ -1761,9 +1757,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 {
@@ -1872,9 +1866,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()