aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2019-03-13 18:20:22 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 21:32:58 +0800
commita6580f578e49463eea0e3e89ab0a1c598c3b9ab6 (patch)
treed2d19cf7b77e79f3e6ccac1a3e972cf76ece96d8 /core
parent3ac5e2363b00fde97288baa173c3d89c1b2e5ec1 (diff)
downloaddexon-a6580f578e49463eea0e3e89ab0a1c598c3b9ab6.tar.gz
dexon-a6580f578e49463eea0e3e89ab0a1c598c3b9ab6.tar.zst
dexon-a6580f578e49463eea0e3e89ab0a1c598c3b9ab6.zip
core: vm: create new oracle contract instance in each call (#251)
Since the VM might be called from different source (downloader, RPC, etc.). We need to make the call state separate. Modify the calling sequence so a new oracle contract instance is used on each run.
Diffstat (limited to 'core')
-rw-r--r--core/vm/evm.go2
-rw-r--r--core/vm/oracle.go8
-rw-r--r--core/vm/oracle_contracts_test.go12
3 files changed, 16 insertions, 6 deletions
diff --git a/core/vm/evm.go b/core/vm/evm.go
index 6b2844020..baf3a0ac9 100644
--- a/core/vm/evm.go
+++ b/core/vm/evm.go
@@ -49,7 +49,7 @@ type (
func run(evm *EVM, contract *Contract, input []byte, readOnly bool) ([]byte, error) {
if contract.CodeAddr != nil {
if o := OracleContracts[*contract.CodeAddr]; o != nil {
- return RunOracleContract(o, evm, input, contract)
+ return RunOracleContract(o(), evm, input, contract)
}
precompiles := PrecompiledContractsHomestead
if evm.ChainConfig().IsByzantium(evm.BlockNumber) {
diff --git a/core/vm/oracle.go b/core/vm/oracle.go
index 81755cd9b..0d4c10d9e 100644
--- a/core/vm/oracle.go
+++ b/core/vm/oracle.go
@@ -38,9 +38,11 @@ type OracleContract interface {
}
// A map representing available system oracle contracts.
-var OracleContracts = map[common.Address]OracleContract{
- GovernanceContractAddress: &GovernanceContract{
- coreDKGUtils: &defaultCoreDKGUtils{},
+var OracleContracts = map[common.Address]func() OracleContract{
+ GovernanceContractAddress: func() OracleContract {
+ return &GovernanceContract{
+ coreDKGUtils: &defaultCoreDKGUtils{},
+ }
},
}
diff --git a/core/vm/oracle_contracts_test.go b/core/vm/oracle_contracts_test.go
index f8f327a68..0b8b7b4f7 100644
--- a/core/vm/oracle_contracts_test.go
+++ b/core/vm/oracle_contracts_test.go
@@ -195,7 +195,11 @@ func (g *OracleContractsTestSuite) SetupTest() {
}
func (g *OracleContractsTestSuite) TearDownTest() {
- OracleContracts[GovernanceContractAddress].(*GovernanceContract).coreDKGUtils = &defaultCoreDKGUtils{}
+ OracleContracts[GovernanceContractAddress] = func() OracleContract {
+ return &GovernanceContract{
+ coreDKGUtils: &defaultCoreDKGUtils{},
+ }
+ }
}
func (g *OracleContractsTestSuite) newPrefundAccount() (*ecdsa.PrivateKey, common.Address) {
@@ -936,7 +940,11 @@ func (g *OracleContractsTestSuite) TestResetDKG() {
mock := &testCoreMock{
tsigReturn: true,
}
- OracleContracts[GovernanceContractAddress].(*GovernanceContract).coreDKGUtils = mock
+ OracleContracts[GovernanceContractAddress] = func() OracleContract {
+ return &GovernanceContract{
+ coreDKGUtils: mock,
+ }
+ }
// Fill data for previous rounds.
roundHeight := int64(g.config.RoundLength)