Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions tests/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"reflect"
"strings"
"testing"
"time"

"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb"
Expand Down Expand Up @@ -192,12 +193,14 @@ func runBenchmark(b *testing.B, t *StateTest) {
b.Error(err)
return
}
var rules = config.Rules(new(big.Int), false)

vmconfig.ExtraEips = eips
block := t.genesis(config).ToBlock(nil)
_, statedb := MakePreState(rawdb.NewMemoryDatabase(), t.json.Pre, false)

var baseFee *big.Int
if config.IsLondon(new(big.Int)) {
if rules.IsLondon {
baseFee = t.json.Env.BaseFee
if baseFee == nil {
// Retesteth uses `0x10` for genesis baseFee. Therefore, it defaults to
Expand Down Expand Up @@ -238,17 +241,40 @@ func runBenchmark(b *testing.B, t *StateTest) {
sender := vm.NewContract(vm.AccountRef(msg.From()), vm.AccountRef(msg.From()),
nil, 0)

var (
gasUsed uint64
elapsed uint64
refund uint64
)
b.ResetTimer()
for n := 0; n < b.N; n++ {
// Execute the message.
snapshot := statedb.Snapshot()
_, _, err = evm.Call(sender, *msg.To(), msg.Data(), msg.Gas(), msg.Value())
if rules.IsBerlin {
statedb.PrepareAccessList(msg.From(), msg.To(), vm.ActivePrecompiles(rules), msg.AccessList())
}
b.StartTimer()
start := time.Now()
Comment on lines +255 to +256
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so annoying. The b has a duration field which we cannot reach, so have to do this whole parallel timekeeping work. Would be nice to somehow get around that, but I don't know how.


// Execute the message.
_, leftOverGas, err := evm.Call(sender, *msg.To(), msg.Data(), msg.Gas(), msg.Value())
if err != nil {
b.Error(err)
return
}

b.StopTimer()
elapsed += uint64(time.Since(start))
refund += statedb.GetRefund()
gasUsed += msg.Gas() - leftOverGas

statedb.RevertToSnapshot(snapshot)
}
if elapsed < 1 {
elapsed = 1
}
// Keep it as uint64, multiply 100 to get two digit float later
mgasps := (100 * 1000 * (gasUsed - refund)) / elapsed
b.ReportMetric(float64(mgasps)/100, "mgas/s")
})
}
}