Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
24a041e
fix genesis issues of write-evm-erigon branch
Jun 13, 2022
b90b990
add logger
Jun 14, 2022
3959559
fix logger
Jun 14, 2022
6113443
add addrPreImAddrNotMatches and accountLimit
Jun 14, 2022
6ff8453
spawn plainstate only
Jun 14, 2022
294d21e
replace etrie with benchtrie to avoid unneccssary prints for debuging
Jun 14, 2022
fd59152
remove unneccessary prints
Jun 14, 2022
a3d567a
add accountLimit flag
Jun 15, 2022
54af3bf
add log prints
Jun 15, 2022
b70765e
minor fix
Jun 15, 2022
1a119bd
preimages[accHash] does not match bytesToAddress(accHash)
Jun 16, 2022
447c5fe
fix erigonaccountLimitFlag
Jun 16, 2022
0caf4f3
minor fixes
Jun 16, 2022
3852362
some fix
Jun 16, 2022
a97686c
replace SetupDB with MakeChainDatabase
Jun 16, 2022
b524cad
erigon write/read cli commands
Jun 18, 2022
65b056c
erigon write/read minor fixes
Jun 18, 2022
872e781
count the number of invocations of EvmDB Iterator while exporting gen…
Jul 1, 2022
5f65803
skip epoch and block processing while exporting genesis
Jul 4, 2022
e42ae0c
minor update
Jul 5, 2022
b574115
introduce ticker
Jul 6, 2022
4c47488
write preimages into kv.Senders
Jul 8, 2022
85b8c85
fix traverseSnapshot
Jul 8, 2022
b0faaf4
test scenario to iterate over snapshot without writing to erigon table
Jul 12, 2022
d25605c
track number of accounts in snapshot iterator
Jul 12, 2022
7b4cfaf
implement buffer to write data into erigon table in a sorted fashion
Jul 12, 2022
c6aec0c
add error description to readErigon
Jul 13, 2022
4e33121
fix ReadErigonTable
Jul 13, 2022
f90fb13
debug ReadErigonTable
Jul 13, 2022
ae68929
try ot use tx.Cursor insteaf of tx.DupSortCursor
Jul 13, 2022
101a4db
add defer to traverseSnapshot
Jul 13, 2022
ba112c6
add tx.Commit to traverseSnapshot
Jul 13, 2022
e2ed2d7
fix ReadErigonTable
Jul 13, 2022
c1f8b47
add second for loop in ReadErigonTable
Jul 13, 2022
a21c9aa
count dupRecords in ReadErigonTable
Jul 13, 2022
ef6d858
update for loops at ReadErigonTable
Jul 13, 2022
30b5639
experiment with cursor
Jul 13, 2022
484b1e8
debugging
Jul 13, 2022
6f09ff0
update algo in ReadErigonTable
Jul 13, 2022
018cfe2
minor improvements
Jul 13, 2022
af6d5e6
check if buffer has duplicated keys
Jul 13, 2022
49e9b3d
adjust erigon write and read for non duplicated keys
Jul 13, 2022
f3b4eee
minor improvements
Jul 13, 2022
d615fe0
count storage records
Jul 13, 2022
a400507
minor fixes
Jul 13, 2022
558cef9
add erigon command to makefile
Jul 13, 2022
1de6eed
buf.writeIntoTable, refactoring, cleaning up
Oct 18, 2022
c0f01ca
set openDatabase label to kv.TxPoolDB
Oct 18, 2022
d01cb30
hardcoded home dir to /var/data for linux
Oct 18, 2022
862ed0c
fix defaultPreimagesPath
Oct 18, 2022
3ad72a6
hardcode datadir for integration.DBProducer
Oct 18, 2022
6385ca2
revert hardcoded datadir for cfg.Node.DataDir and default case in def…
Oct 18, 2022
e354d9d
cleanup
Oct 18, 2022
58787c2
set defaultPreimagesPath
Oct 18, 2022
e784a36
cleanup
Oct 18, 2022
0ab5bc6
delete evmstore/state
Oct 18, 2022
35685e3
hardcode home path and preimages path
Oct 21, 2022
3d3311c
make setup for profiling6
Oct 21, 2022
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
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ opera-image:
docker build \
--network=host \
-f ./docker/Dockerfile.opera -t "opera:$(TAG)" .

erigon:
./build/opera preimages write
./build/opera erigon write
./build/opera erigon read
.PHONY: test
test:
go test ./...
Expand Down
61 changes: 61 additions & 0 deletions cmd/opera/launcher/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package launcher
import (
"github.com/ethereum/go-ethereum/cmd/utils"
"gopkg.in/urfave/cli.v1"
//"github.com/Fantom-foundation/go-opera/gossip/erigon"
)

var (
Expand All @@ -11,6 +12,7 @@ var (
Usage: `EVM export mode ("full" or "ext-mpt" or "mpt" or "none")`,
Value: "mpt",
}

importCommand = cli.Command{
Name: "import",
Usage: "Import a blockchain file",
Expand Down Expand Up @@ -116,4 +118,63 @@ Checks EVM storage roots and code hashes
},
},
}

erigonCommand = cli.Command{
Name: "erigon",
Usage: "Write/Read EVM data into/from Erigon kv.PlainState table",
Category: "MISCELLANEOUS COMMANDS",
//Action: utils.MigrateFlags(writeEVMToErigon),
Subcommands: []cli.Command{
{
Name: "write",
Usage: "Write EVM accounts to erigon database",
Action: utils.MigrateFlags(writeErigon),
Description: `
opera erigon write
`,
},
{
Name: "read",
Usage: "Read EVM accounts from erigon database",
Action: utils.MigrateFlags(readErigon),
Description: `
opera erigon read
`,
},
},

Description: `
opera erigon

The erigon command iterates over MPT data and flushes it into Erigon tables`,
}

preimagesCommand = cli.Command{
Name: "preimages",
Usage: "Write/Read preimages into/from Erigon kv.Senders table",
Category: "MISCELLANEOUS COMMANDS",
//Action: utils.MigrateFlags(writeEVMToErigon),
Subcommands: []cli.Command{
{
Name: "write",
Usage: "Write preimages to erigon table",
Action: utils.MigrateFlags(writePreimagesCmd),
Description: `
opera preimages write
`,
},
{
Name: "read",
Usage: "Read EVM preimages from erigon table",
Action: utils.MigrateFlags(readPreimagesCmd),
Description: `
opera preimages read
`,
},
},
Description: `
opera preimages

The erigon command iterates over MPT data and flushes it into Erigon tables`,
}
)
78 changes: 78 additions & 0 deletions cmd/opera/launcher/erigoncmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package launcher

import (
"context"
//"fmt"
"fmt"
"path"
"time"

"gopkg.in/urfave/cli.v1"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"

"github.com/Fantom-foundation/go-opera/gossip/erigon"
"github.com/Fantom-foundation/go-opera/integration"
"github.com/Fantom-foundation/go-opera/logger"

"github.com/ledgerwatch/erigon-lib/kv"
)

func readErigon(_ *cli.Context) error {

db := erigon.MakeChainDatabase(logger.New("mdbx"))
defer db.Close()

tx, err := db.BeginRo(context.Background())
if err != nil {
return fmt.Errorf("unable to begin transaction, err: %q", err)
}
defer tx.Rollback()

if err := erigon.ReadErigonTableNoDups(kv.PlainState, tx); err != nil {
return fmt.Errorf("unable to read from Erigon table, err: %q", err)
}

// TODO handle flags
return nil
}

func writeErigon(ctx *cli.Context) error {

start := time.Now()
log.Info("Writing of EVM accounts into Erigon database started")

// initiate erigon database
db := erigon.MakeChainDatabase(logger.New("mdbx"))
defer db.Close()

cfg := makeAllConfigs(ctx)

rawProducer := integration.DBProducer(path.Join(erigon.DefaultDataDir(), "chaindata"), cacheScaler(ctx))

gdb, err := makeRawGossipStore(rawProducer, cfg)
if err != nil {
log.Crit("DB opening error", "datadir", cfg.Node.DataDir, "err", err)
}
if gdb.GetHighestLamport() != 0 {
log.Warn("Attempting genesis export not in a beginning of an epoch. Genesis file output may contain excessive data.")
}
defer gdb.Close()

log.Info("Getting EvmDb")
chaindb := gdb.EvmStore().EvmDb

log.Info("Getting FinalizedStateRoot")
root := common.Hash(gdb.GetBlockState().FinalizedStateRoot)

log.Info("Getting LastBlock")
lastBlockIdx := gdb.GetBlockState().LastBlock.Idx

log.Info("Generate Erigon Plain State...")
if err := erigon.GeneratePlainState(root, chaindb, db, lastBlockIdx); err != nil {
return err
}
log.Info("Generation of Erigon Plain State is complete", "elapsed", common.PrettyDuration(time.Since(start)))
return nil
}
120 changes: 62 additions & 58 deletions cmd/opera/launcher/genesiscmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"gopkg.in/urfave/cli.v1"

"github.com/Fantom-foundation/go-opera/gossip/evmstore"
"github.com/Fantom-foundation/go-opera/inter/ibr"
"github.com/Fantom-foundation/go-opera/inter/ier"
"github.com/Fantom-foundation/go-opera/opera/genesis"
"github.com/Fantom-foundation/go-opera/opera/genesisstore"
"github.com/Fantom-foundation/go-opera/opera/genesisstore/fileshash"
Expand Down Expand Up @@ -243,78 +241,84 @@ func exportGenesis(ctx *cli.Context) error {
if to > gdb.GetEpoch() {
to = gdb.GetEpoch()
}

toBlock := idx.Block(0)
fromBlock := idx.Block(0)
{
log.Info("Exporting epochs", "from", from, "to", to)
writer := newUnitWriter(plain)
err := writer.Start(header, genesisstore.EpochsSection, tmpPath)
if err != nil {
return err
}
for i := to; i >= from; i-- {
er := gdb.GetFullEpochRecord(i)
if er == nil {
log.Warn("No epoch record", "epoch", i)
break
}
b, _ := rlp.EncodeToBytes(ier.LlrIdxFullEpochRecord{
LlrFullEpochRecord: *er,
Idx: i,
})
_, err := writer.Write(b)
/*
{
log.Info("Exporting epochs", "from", from, "to", to)
writer := newUnitWriter(plain)
err := writer.Start(header, genesisstore.EpochsSection, tmpPath)
if err != nil {
return err
}
if i == from {
fromBlock = er.BlockState.LastBlock.Idx
for i := to; i >= from; i-- {
er := gdb.GetFullEpochRecord(i)
if er == nil {
log.Warn("No epoch record", "epoch", i)
break
}
b, _ := rlp.EncodeToBytes(ier.LlrIdxFullEpochRecord{
LlrFullEpochRecord: *er,
Idx: i,
})
_, err := writer.Write(b)
if err != nil {
return err
}
if i == from {
fromBlock = er.BlockState.LastBlock.Idx
}
if i == to {
toBlock = er.BlockState.LastBlock.Idx
}
}
if i == to {
toBlock = er.BlockState.LastBlock.Idx
epochsHash, err = writer.Flush()
if err != nil {
return err
}
log.Info("Exported epochs", "hash", epochsHash.String())
}
epochsHash, err = writer.Flush()
if err != nil {
return err
}
log.Info("Exported epochs", "hash", epochsHash.String())
}
*/

if fromBlock < 1 {
// avoid underflow
fromBlock = 1
}
{
log.Info("Exporting blocks", "from", fromBlock, "to", toBlock)
writer := newUnitWriter(plain)
err := writer.Start(header, genesisstore.BlocksSection, tmpPath)
if err != nil {
return err
/*
if fromBlock < 1 {
// avoid underflow
fromBlock = 1
}
for i := toBlock; i >= fromBlock; i-- {
br := gdb.GetFullBlockRecord(i)
if br == nil {
log.Warn("No block record", "block", i)
break
{
log.Info("Exporting blocks", "from", fromBlock, "to", toBlock)
writer := newUnitWriter(plain)
err := writer.Start(header, genesisstore.BlocksSection, tmpPath)
if err != nil {
return err
}
if i%200000 == 0 {
log.Info("Exporting blocks", "last", i)
for i := toBlock; i >= fromBlock; i-- {
br := gdb.GetFullBlockRecord(i)
if br == nil {
log.Warn("No block record", "block", i)
break
}
if i%200000 == 0 {
log.Info("Exporting blocks", "last", i)
}
b, _ := rlp.EncodeToBytes(ibr.LlrIdxFullBlockRecord{
LlrFullBlockRecord: *br,
Idx: i,
})
_, err := writer.Write(b)
if err != nil {
return err
}
}
b, _ := rlp.EncodeToBytes(ibr.LlrIdxFullBlockRecord{
LlrFullBlockRecord: *br,
Idx: i,
})
_, err := writer.Write(b)
blocksHash, err = writer.Flush()
if err != nil {
return err
}
log.Info("Exported blocks", "hash", blocksHash.String())
}
blocksHash, err = writer.Flush()
if err != nil {
return err
}
log.Info("Exported blocks", "hash", blocksHash.String())
}

*/

if mode != "none" {
log.Info("Exporting EVM data", "from", fromBlock, "to", toBlock)
Expand Down
4 changes: 4 additions & 0 deletions cmd/opera/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ func init() {
snapshotCommand,
// See dbcmd.go
dbCommand,
// See fixdirty.go
//fixDirtyCommand,
erigonCommand,
preimagesCommand,
}
sort.Sort(cli.CommandsByName(app.Commands))

Expand Down
51 changes: 51 additions & 0 deletions cmd/opera/launcher/preimagescmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package launcher

import (
"context"
"fmt"
"time"

"gopkg.in/urfave/cli.v1"

"github.com/Fantom-foundation/go-opera/gossip/erigon"
"github.com/Fantom-foundation/go-opera/logger"

"github.com/ethereum/go-ethereum/log"

"github.com/ledgerwatch/erigon/common"

"github.com/ledgerwatch/erigon-lib/kv"
)

func writePreimagesCmd(_ *cli.Context) error {
start := time.Now()

db := erigon.MakeChainDatabase(logger.New("mdbx"))
defer db.Close()

if err := erigon.WritePreimagesToSenders(db); err != nil {
return fmt.Errorf("Import error: %q", err)
}

log.Info("Writing preimages is complete", "elapsed", common.PrettyDuration(time.Since(start)))

return nil
}

func readPreimagesCmd(_ *cli.Context) error {

db := erigon.MakeChainDatabase(logger.New("mdbx"))
defer db.Close()

tx, err := db.BeginRo(context.Background())
if err != nil {
return err
}
defer tx.Rollback()

if err := erigon.ReadErigonTableNoDups(kv.Senders, tx); err != nil {
return err
}

return nil
}
1 change: 1 addition & 0 deletions debug/loudpanic.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

//go:build go1.6
// +build go1.6

package debug
Expand Down
1 change: 1 addition & 0 deletions debug/loudpanic_fallback.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

//go:build !go1.6
// +build !go1.6

package debug
Expand Down
Loading