Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor for the new version of the Substate #7

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion cmd/cmdtest/test_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (tt *TestCmd) Run(name string, args ...string) {
// InputLine writes the given text to the childs stdin.
// This method can also be called from an expect template, e.g.:
//
// cli.expect(`Passphrase: {{.InputLine "password"}}`)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This file seems to be modified by auto-formatting tool. I would suggest remove files which are unrelated to this change.

// cli.expect(`Passphrase: {{.InputLine "password"}}`)
func (tt *TestCmd) InputLine(s string) string {
io.WriteString(tt.stdin, s+"\n")
return ""
Expand Down
14 changes: 9 additions & 5 deletions cmd/opera/launcher/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (
"syscall"
"time"

substate "github.com/Fantom-foundation/Substate"
"github.com/Fantom-foundation/go-opera/evmcore"
"github.com/Fantom-foundation/go-opera/gossip"
"github.com/Fantom-foundation/go-opera/gossip/emitter"
"github.com/Fantom-foundation/go-opera/inter"
"github.com/Fantom-foundation/go-opera/opera/genesisstore"
"github.com/Fantom-foundation/go-opera/substate"
"github.com/Fantom-foundation/go-opera/utils/ioread"
"github.com/Fantom-foundation/lachesis-base/hash"
"github.com/Fantom-foundation/lachesis-base/inter/idx"
Expand Down Expand Up @@ -79,10 +79,14 @@ func importEvents(ctx *cli.Context) error {

if ctx.Bool(RecordingFlag.Name) {
// OpenSubstateDB
substate.RecordReplay = true
substate.SetSubstateDb(ctx.String(SubstateDbFlag.Name))
substate.OpenSubstateDB()
defer substate.CloseSubstateDB()
if !substate.RecordReplay {
substate.RecordReplay = true
err := substate.NewSubstateDB(ctx.String(SubstateDbFlag.Name))
if err != nil {
return err
}
defer substate.CloseSubstateDB()
}
}

if ctx.Bool(ProfileEVMCallFlag.Name) {
Expand Down
11 changes: 6 additions & 5 deletions cmd/opera/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"
"time"

substate "github.com/Fantom-foundation/Substate"
"github.com/Fantom-foundation/lachesis-base/inter/idx"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore"
Expand All @@ -32,6 +31,7 @@ import (
"github.com/Fantom-foundation/go-opera/integration"
"github.com/Fantom-foundation/go-opera/opera/genesis"
"github.com/Fantom-foundation/go-opera/opera/genesisstore"
"github.com/Fantom-foundation/go-opera/substate"
"github.com/Fantom-foundation/go-opera/utils/errlock"
"github.com/Fantom-foundation/go-opera/valkeystore"
_ "github.com/Fantom-foundation/go-opera/version"
Expand Down Expand Up @@ -278,11 +278,12 @@ func lachesisMain(ctx *cli.Context) error {
//}
//defer tracingStop()

if ctx.Bool(RecordingFlag.Name) {
// OpenSubstateDB
if !substate.RecordReplay {
substate.RecordReplay = true
substate.SetSubstateDb(ctx.String(SubstateDbFlag.Name))
substate.OpenSubstateDB()
err := substate.NewSubstateDB(ctx.String(SubstateDbFlag.Name))
if err != nil {
return err
}
defer substate.CloseSubstateDB()
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/opera/launcher/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ func SetDataDir(datadir string) {

func measureDbDir(name, datadir string) {
var (
dbSize atomic.Int64
gauge metrics.Gauge
dbSize atomic.Int64
gauge metrics.Gauge
rescan = (len(datadir) > 0 && datadir != "inmemory")
)
for {
Expand Down
46 changes: 40 additions & 6 deletions evmcore/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ import (
"math"
"math/big"

substate "github.com/Fantom-foundation/Substate"
"github.com/Fantom-foundation/Substate/substate"
stypes "github.com/Fantom-foundation/Substate/types"
"github.com/Fantom-foundation/Substate/types/hash"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"

innerSubstate "github.com/Fantom-foundation/go-opera/substate"
"github.com/Fantom-foundation/go-opera/utils/signers/gsignercache"
"github.com/Fantom-foundation/go-opera/utils/signers/internaltx"
)
Expand Down Expand Up @@ -101,17 +104,48 @@ func (p *StateProcessor) Process(
if err != nil {
return nil, nil, nil, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err)
}
if substate.RecordReplay {
if innerSubstate.RecordReplay {
// save tx substate into DBs, merge block hashes to env
etherBlock := block.RecordingEthBlock()
to := stypes.Address(msg.To().Bytes())
dataHash := hash.Keccak256Hash(msg.Data())
recording := substate.NewSubstate(
statedb.SubstatePreAlloc,
statedb.SubstatePostAlloc,
substate.NewSubstateEnv(etherBlock, statedb.SubstateBlockHashes),
substate.NewSubstateMessage(&msg),
substate.NewSubstateResult(receipt),
substate.NewEnv(
stypes.Address(etherBlock.Coinbase()),
etherBlock.Difficulty(),
etherBlock.GasLimit(),
etherBlock.NumberU64(),
etherBlock.Time(),
etherBlock.BaseFee(),
innerSubstate.HashGethToSubstate(statedb.SubstateBlockHashes)),
substate.NewMessage(
msg.Nonce(),
msg.IsFake(),
msg.GasPrice(),
msg.Gas(),
stypes.Address(msg.From()),
&to,
msg.Value(),
msg.Data(),
&dataHash,
innerSubstate.AccessListGethToSubstate(msg.AccessList()),
msg.GasFeeCap(),
msg.GasTipCap()),
substate.NewResult(
receipt.Status,
receipt.Bloom.Bytes(),
innerSubstate.LogsGethToSubstate(receipt.Logs),
stypes.Address(receipt.ContractAddress),
receipt.GasUsed),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Each New function takes long arguments. I want to suggest moving them to the substate package.

blockNumber.Uint64(),
txCounter,
)
substate.PutSubstate(block.NumberU64(), txCounter, recording)
err = innerSubstate.PutSubstate(recording)
if err != nil {
return nil, nil, nil, fmt.Errorf("could not put substate %d [%v]: %w", i, tx.Hash().Hex(), err)
}
}
txCounter++
receipts = append(receipts, receipt)
Expand Down
22 changes: 12 additions & 10 deletions evmcore/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/ethereum/go-ethereum/params"
)

// Profile EVM Call
// Profile EVM Call
var ProfileEVMCall bool

var emptyCodeHash = crypto.Keccak256Hash(nil)
Expand All @@ -46,8 +46,10 @@ The state transitioning model does all the necessary work to work out a valid ne
3) Create a new state object if the recipient is \0*32
4) Value transfer
== If contract creation ==
4a) Attempt to run transaction data
4b) If valid, use result as code for the new state object

4a) Attempt to run transaction data
4b) If valid, use result as code for the new state object

== end ==
5) Run Script section
6) Derive new state root
Expand Down Expand Up @@ -236,13 +238,13 @@ func (st *StateTransition) internal() bool {
// TransitionDb will transition the state by applying the current message and
// returning the evm execution result with following fields.
//
// - used gas:
// total gas used (including gas being refunded)
// - returndata:
// the returned data from evm
// - concrete execution error:
// various **EVM** error which aborts the execution,
// e.g. ErrOutOfGas, ErrExecutionReverted
// - used gas:
// total gas used (including gas being refunded)
// - returndata:
// the returned data from evm
// - concrete execution error:
// various **EVM** error which aborts the execution,
// e.g. ErrOutOfGas, ErrExecutionReverted
//
// However if any consensus issue encountered, return the error directly with
// nil evm execution result.
Expand Down
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module github.com/Fantom-foundation/go-opera

go 1.17
go 1.21

require (
github.com/Fantom-foundation/Substate v0.0.0-20230512151613-f039b23bf3f7
github.com/Fantom-foundation/Substate v0.0.0-20240328090846-4abefcad12de
github.com/Fantom-foundation/lachesis-base v0.0.0-20221208123620-82a6d15f995c
github.com/allegro/bigcache v1.2.1 // indirect
github.com/certifi/gocertifi v0.0.0-20191021191039-0944d244cd40 // indirect
Expand Down Expand Up @@ -40,9 +40,9 @@ require (
github.com/uber/jaeger-client-go v2.20.1+incompatible
github.com/uber/jaeger-lib v2.2.0+incompatible
go.uber.org/atomic v1.5.1 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a
golang.org/x/tools v0.1.5 // indirect
golang.org/x/crypto v0.17.0
golang.org/x/sys v0.15.0
golang.org/x/tools v0.6.0 // indirect
gopkg.in/urfave/cli.v1 v1.20.0
)

Expand Down Expand Up @@ -102,9 +102,9 @@ require (
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/exp v0.0.0-20200513190911-00229845015e // indirect
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t
github.com/Fantom-foundation/Substate v0.0.0-20230224090651-4c8c024214f4/go.mod h1:/yIHWCDDJcdKMJYvOLdYOnHt5eUBF9XWnrvrNE+90ik=
github.com/Fantom-foundation/Substate v0.0.0-20230512151613-f039b23bf3f7 h1:qLKPsYxwOv7EudpOwPv+l89QqEzzxK0pSPC/+X/AuTw=
github.com/Fantom-foundation/Substate v0.0.0-20230512151613-f039b23bf3f7/go.mod h1:KoObQO1Wmf3ACjxcXDREHf+mtDF4MAXfHwtxMIdyhx8=
github.com/Fantom-foundation/Substate v0.0.0-20240328090846-4abefcad12de h1:qMlYkRK1EPWykms8cby5kb+mqHD58/zXE+rqXftcbQc=
github.com/Fantom-foundation/Substate v0.0.0-20240328090846-4abefcad12de/go.mod h1:4rE8IlDP0uBEfvgQwQuf+g0ngmSG/BKBkIWmzxj1a6c=
github.com/Fantom-foundation/go-ethereum-substate v1.1.1-0.20230301033351-d20d976d1f4c h1:vA5wxnBTXJBuNtlvLe//aNIBEAHrgOKuB3BuA5bx+qE=
github.com/Fantom-foundation/go-ethereum-substate v1.1.1-0.20230301033351-d20d976d1f4c/go.mod h1:Hu8U9SrXP6ABqtSNfJHw8lRGnr6tyma9PNZvwTweDjQ=
github.com/Fantom-foundation/lachesis-base v0.0.0-20221208123620-82a6d15f995c h1:hgy6GWSddbPyLxRLMykSEImCqv+XuXgLYbqOgI1CBvk=
Expand Down Expand Up @@ -693,6 +695,7 @@ golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWP
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -774,6 +777,7 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d h1:20cMwl2fHAzkJMEA+8J4JgqBQcQGzbisXo31MIeenXI=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand All @@ -792,6 +796,7 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -855,6 +860,7 @@ golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -867,6 +873,7 @@ golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down Expand Up @@ -928,6 +935,7 @@ golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
6 changes: 3 additions & 3 deletions gossip/evmstore/evmpruner/pruner.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ const (
// Pruner is an offline tool to prune the stale state with the
// help of the snapshot. The workflow of pruner is very simple:
//
// - iterate the snapshot, reconstruct the relevant state
// - iterate the database, delete all other state entries which
// don't belong to the target state and the genesis state
// - iterate the snapshot, reconstruct the relevant state
// - iterate the database, delete all other state entries which
// don't belong to the target state and the genesis state
//
// It can take several hours(around 2 hours for mainnet) to finish
// the whole pruning work. It's recommended to run this offline tool
Expand Down
27 changes: 27 additions & 0 deletions substate/substate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package substate

import (
"github.com/syndtr/goleveldb/leveldb/opt"

"github.com/Fantom-foundation/Substate/db"
"github.com/Fantom-foundation/Substate/substate"
)

var (
staticSubstateDB db.SubstateDB
RecordReplay bool = false
)

func NewSubstateDB(path string) error {
var err error
staticSubstateDB, err = db.NewSubstateDB(path, &opt.Options{ReadOnly: false}, nil, nil)
return err
}

func CloseSubstateDB() error {
return staticSubstateDB.Close()
}

func PutSubstate(ss *substate.Substate) error {
return staticSubstateDB.PutSubstate(ss)
}
50 changes: 50 additions & 0 deletions substate/utils.go
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see a full copy of a structure in the util function. Can you and @matejmlejnek double check on performance penalty when recording new substates?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this is our package, please add unit tests.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package substate

import (
stypes "github.com/Fantom-foundation/Substate/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)

//Here I put some utils to convert Geth types to Substate types

func HashGethToSubstate(g map[uint64]common.Hash) map[uint64]stypes.Hash {
res := make(map[uint64]stypes.Hash)
for k, v := range g {
res[k] = stypes.Hash(v)
}
return res
}

func AccessListGethToSubstate(al types.AccessList) stypes.AccessList {
st := stypes.AccessList{}
for _, tuple := range al {
var keys []stypes.Hash
for _, key := range tuple.StorageKeys {
keys = append(keys, stypes.Hash(key))
}
st = append(st, stypes.AccessTuple{Address: stypes.Address(tuple.Address), StorageKeys: keys})
}
return st
}

func LogsGethToSubstate(logs []*types.Log) []*stypes.Log {
var ls []*stypes.Log
for _, log := range logs {
l := new(stypes.Log)
l.BlockHash = stypes.Hash(log.BlockHash)
l.Data = log.Data
l.Address = stypes.Address(log.Address)
l.Index = log.Index
l.BlockNumber = log.BlockNumber
l.Removed = log.Removed
l.TxHash = stypes.Hash(log.TxHash)
l.TxIndex = log.TxIndex
for _, topic := range log.Topics {
l.Topics = append(l.Topics, stypes.Hash(topic))
}

ls = append(ls, l)
}
return ls
}
1 change: 0 additions & 1 deletion utils/dbutil/compactdb/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func TestTrimAfterDiff(t *testing.T) {
require.Equal(t, []byte{}, a)
require.Equal(t, []byte{}, b)


a, b = trimAfterDiff([]byte{1, 2}, []byte{1, 3}, 1)
require.Equal(t, []byte{1, 2}, a)
require.Equal(t, []byte{1, 3}, b)
Expand Down