mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
Fix compilation, small improvements
This commit is contained in:
parent
2f4a259c56
commit
77aea4f0d9
1 changed files with 26 additions and 29 deletions
|
|
@ -17,48 +17,44 @@
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/big"
|
|
||||||
"testing"
|
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"math/big"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
codefile string
|
codefile string
|
||||||
input string
|
input string
|
||||||
expected string
|
expected string
|
||||||
)
|
)
|
||||||
|
|
||||||
var testVMConfig = func() vm.Config {
|
var flagsParsed = func() bool {
|
||||||
vmconfig := vm.Config{}
|
|
||||||
flag.StringVar(&codefile, "codefile", "", "EVM code to run")
|
flag.StringVar(&codefile, "codefile", "", "EVM code to run")
|
||||||
flag.StringVar(&input, "input", "", "input calldata")
|
flag.StringVar(&input, "input", "", "input calldata")
|
||||||
flag.StringVar(&expected, "expected", "", "expected return data")
|
flag.StringVar(&expected, "expected", "", "expected return data")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
// don't actually need this vmconfig, but we need to parse custom command args in some way like this
|
return true
|
||||||
return vmconfig
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
||||||
func BenchmarkEvmCode(b *testing.B) {
|
func BenchmarkEvmCode(b *testing.B) {
|
||||||
|
|
||||||
state, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
|
state, _ := state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase()))
|
||||||
address := common.HexToAddress("0x0a")
|
address := common.HexToAddress("0x0a")
|
||||||
|
|
||||||
var (
|
var (
|
||||||
codebytes []byte
|
codebytes []byte
|
||||||
err error
|
err error
|
||||||
ret []byte
|
ret []byte
|
||||||
codehex []byte
|
codehex []byte
|
||||||
gasLeft uint64
|
gasLeft uint64
|
||||||
)
|
)
|
||||||
|
|
||||||
fmt.Println("codefile:", codefile)
|
fmt.Println("codefile:", codefile)
|
||||||
|
|
@ -71,32 +67,33 @@ func BenchmarkEvmCode(b *testing.B) {
|
||||||
} else {
|
} else {
|
||||||
panic("Need to pass --codefile arg!")
|
panic("Need to pass --codefile arg!")
|
||||||
}
|
}
|
||||||
|
|
||||||
codehexstr := string(codehex)
|
codehexstr := string(codehex)
|
||||||
|
|
||||||
fmt.Println("code hex length:", len(codehexstr))
|
fmt.Println("code hex length:", len(codehexstr))
|
||||||
|
|
||||||
codebytes = common.Hex2Bytes(codehexstr)
|
codebytes = common.Hex2Bytes(codehexstr)
|
||||||
|
|
||||||
|
|
||||||
state.SetCode(address, codebytes)
|
state.SetCode(address, codebytes)
|
||||||
evmChainConfig := ¶ms.ChainConfig{
|
evmChainConfig := ¶ms.ChainConfig{
|
||||||
ChainID: big.NewInt(1),
|
ChainID: big.NewInt(1),
|
||||||
HomesteadBlock: new(big.Int),
|
HomesteadBlock: new(big.Int),
|
||||||
DAOForkBlock: new(big.Int),
|
DAOForkBlock: new(big.Int),
|
||||||
DAOForkSupport: false,
|
DAOForkSupport: false,
|
||||||
EIP150Block: new(big.Int),
|
EIP150Block: new(big.Int),
|
||||||
EIP155Block: new(big.Int),
|
EIP155Block: new(big.Int),
|
||||||
EIP158Block: new(big.Int),
|
EIP158Block: new(big.Int),
|
||||||
ByzantiumBlock: big.NewInt(0),
|
ByzantiumBlock: big.NewInt(0),
|
||||||
ConstantinopleBlock: big.NewInt(0),
|
ConstantinopleBlock: big.NewInt(0),
|
||||||
};
|
}
|
||||||
|
|
||||||
startGas := uint64(100000000) // 100 million
|
startGas := uint64(100000000) // 100 million
|
||||||
|
inputBytes := common.Hex2Bytes(input)
|
||||||
|
config := &Config{ChainConfig: evmChainConfig, State: state, EVMConfig: vm.Config{}, GasLimit: startGas}
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
ret, gasLeft, err = Call(address, common.Hex2Bytes(input), &Config{ChainConfig: evmChainConfig, State: state, EVMConfig: testVMConfig, GasLimit: startGas})
|
ret, gasLeft, err = Call(address, inputBytes, config)
|
||||||
}
|
}
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
//Check if it is correct
|
//Check if it is correct
|
||||||
|
|
@ -114,4 +111,4 @@ func BenchmarkEvmCode(b *testing.B) {
|
||||||
gasUsed := startGas - gasLeft
|
gasUsed := startGas - gasLeft
|
||||||
fmt.Println("gasUsed:", gasUsed)
|
fmt.Println("gasUsed:", gasUsed)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue