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

[DO NOT MERGE] Verkle Gen Devnet 6 #9335

Draft
wants to merge 39 commits into
base: release/2.60
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b87542e
Save progress
Dec 4, 2023
23a2cd8
Genesis root calc with in-memory vtrie
Dec 7, 2023
bb0dacf
Fork id + goodpeers + verkle refac
Dec 13, 2023
d1b38eb
Working height 42
Dec 21, 2023
099dede
Progress till height 7196
somnathb1 Dec 23, 2023
653b42e
Upto 7196
somnathb1 Dec 25, 2023
fc1c6ae
Merge branch 'devel' into som/verkle-kaustinen-2
somnathb1 Apr 18, 2024
51c4ee5
Fix merge and update go-verkle
somnathb1 Apr 18, 2024
e32775f
chain-config: capital IsOsaka
somnathb1 Apr 18, 2024
41ed859
Move verkle logic to Osaka
somnathb1 Apr 18, 2024
53e1175
Gas tale updates
somnathb1 Apr 22, 2024
3b5533a
Update gas table
somnathb1 Apr 23, 2024
604f451
Update access_witness
somnathb1 Apr 23, 2024
7bc5882
gofmt
somnathb1 Apr 23, 2024
c1d009a
Merge branch 'devel' into som/verkle-kaustinen-2
somnathb1 Apr 23, 2024
21fc9f9
Skip hashstate stage for verkle
somnathb1 Apr 24, 2024
700a1a5
Merge branch 'devel' into som/verkle-kaustinen-2
somnathb1 Apr 30, 2024
8305d89
Build fix
somnathb1 May 11, 2024
17d379f
Add pre image dump new
somnathb1 May 15, 2024
241cd92
Add new preimage dump func
somnathb1 May 17, 2024
6535bc1
Update network configs to vgdn-6
somnathb1 Jul 1, 2024
f5aaca7
More updates looking at geth
somnathb1 Jul 16, 2024
9787051
Copy more
somnathb1 Jul 29, 2024
94be461
Change to Osakatime in config
somnathb1 Jul 30, 2024
398d836
Add 2935 part 1
somnathb1 May 9, 2024
cc96f6f
Update EIP-2935 for Prague devnet1 (#10920)
yperbasis Jun 26, 2024
c427a90
Merge remote-tracking branch 'origin/release/2.60' into som/verkle-ka…
somnathb1 Aug 29, 2024
a59ef84
Fix rebase
somnathb1 Aug 30, 2024
0d668d3
Working execution Checkpoint
somnathb1 Sep 2, 2024
517d116
Fix precompile for osaka
somnathb1 Sep 3, 2024
b107e29
Rename and default enable SpawnVerkleTrieStage
somnathb1 Sep 4, 2024
95bd102
Sync go-verkle version
somnathb1 Sep 4, 2024
9d2573c
Rename dump_pre_images func
somnathb1 Oct 27, 2024
0d9a520
Remove older methods from verkle/main cmd
somnathb1 Oct 27, 2024
27d9e45
Update command to add hashed keys files
somnathb1 Oct 27, 2024
f958eb0
Devnet-6 update
somnathb1 Oct 31, 2024
b11c75a
Add verkle fork and exec spec tests
somnathb1 Oct 31, 2024
997f46f
Comment unnecessary files for now
somnathb1 Nov 2, 2024
5b5b9b7
Comment out unnecessary actions
somnathb1 Nov 2, 2024
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/state/commands/state_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func StateRoot(ctx context.Context, genesis *types.Genesis, blockNum uint64, dat
if rwTx, err = db.BeginRw(ctx); err != nil {
return err
}
_, genesisIbs, err4 := core.GenesisToBlock(genesis, "")
_, genesisIbs, err4 := core.GenesisToBlock(genesis, "", nil)
if err4 != nil {
return err4
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/state/exec3/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (rw *Worker) RunTxTaskNoLock(txTask *exec22.TxTask) {
if txTask.BlockNum == 0 {
// Genesis block
// fmt.Printf("txNum=%d, blockNum=%d, Genesis\n", txTask.TxNum, txTask.BlockNum)
_, ibs, err = core.GenesisToBlock(rw.genesis, "")
_, ibs, err = core.GenesisToBlock(rw.genesis, "", nil)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/state/exec3/state_recon.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func (rw *ReconWorker) runTxTask(txTask *exec22.TxTask) error {
if txTask.BlockNum == 0 && txTask.TxIndex == -1 {
//fmt.Printf("txNum=%d, blockNum=%d, Genesis\n", txTask.TxNum, txTask.BlockNum)
// Genesis block
_, ibs, err = core.GenesisToBlock(rw.genesis, "")
_, ibs, err = core.GenesisToBlock(rw.genesis, "", nil)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/verkle/verkletrie/incrementAccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ func IncrementAccount(vTx kv.RwTx, tx kv.Tx, workers uint64, verkleWriter *Verkl
}
defer cancelWorkers()

accountCursor, err := tx.CursorDupSort(kv.AccountChangeSet)
accChangesCursor, err := tx.CursorDupSort(kv.AccountChangeSet)
if err != nil {
return err
}
defer accountCursor.Close()
defer accChangesCursor.Close()

// Start Goroutine for collection
go func() {
Expand All @@ -62,7 +62,7 @@ func IncrementAccount(vTx kv.RwTx, tx kv.Tx, workers uint64, verkleWriter *Verkl
marker := NewVerkleMarker(tmpdir)
defer marker.Rollback()

for k, v, err := accountCursor.Seek(hexutility.EncodeTs(from)); k != nil; k, v, err = accountCursor.Next() {
for k, v, err := accChangesCursor.Seek(hexutility.EncodeTs(from)); k != nil; k, v, err = accChangesCursor.Next() {
if err != nil {
return err
}
Expand Down
146 changes: 85 additions & 61 deletions cmd/verkle/verkletrie/verkle_tree_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/core/rawdb"
"github.com/ledgerwatch/erigon/core/types/accounts"
"github.com/ledgerwatch/erigon/turbo/trie/vtree"
"github.com/ledgerwatch/erigon/turbo/trie/vkutils"
)

func int256ToVerkleFormat(x *uint256.Int, buffer []byte) {
Expand All @@ -30,48 +30,71 @@ func int256ToVerkleFormat(x *uint256.Int, buffer []byte) {

func flushVerkleNode(db kv.RwTx, node verkle.VerkleNode, logInterval *time.Ticker, key []byte, logger log.Logger) error {
var err error
totalInserted := 0
node.(*verkle.InternalNode).Flush(func(node verkle.VerkleNode) {
if err != nil {
return
}
// totalInserted := 0
// node.(*verkle.InternalNode).Flush(func(node verkle.VerkleNode) {
// if err != nil {
// return
// }

err = rawdb.WriteVerkleNode(db, node)
// err = rawdb.WriteVerkleNode(db, node)
// if err != nil {
// return
// }
// totalInserted++
// select {
// case <-logInterval.C:
// logger.Info("Flushing Verkle nodes", "inserted", totalInserted, "key", common.Bytes2Hex(key))
// default:
// }
// })

node.(*verkle.InternalNode).Flush(func(path []byte, node verkle.VerkleNode) {
node.Commit()
s, err := node.Serialize()
if err != nil {
return
panic(err)
}
totalInserted++
select {
case <-logInterval.C:
logger.Info("Flushing Verkle nodes", "inserted", totalInserted, "key", common.Bytes2Hex(key))
default:
if err := db.Put(kv.VerkleTrie, path, s); err != nil {
panic(err)
}
})
return err
}

func collectVerkleNode(collector *etl.Collector, node verkle.VerkleNode, logInterval *time.Ticker, key []byte, logger log.Logger) error {
var err error
totalInserted := 0
node.(*verkle.InternalNode).Flush(func(node verkle.VerkleNode) {
if err != nil {
return
}
var encodedNode []byte
// totalInserted := 0
// node.(*verkle.InternalNode).Flush(func(node verkle.VerkleNode) {
// if err != nil {
// return
// }
// var encodedNode []byte

// rootHash := node.Commitment().Bytes()
// encodedNode, err = node.Serialize()
// if err != nil {
// return
// }
// err = collector.Collect(rootHash[:], encodedNode)
// totalInserted++
// select {
// case <-logInterval.C:
// logger.Info("Flushing Verkle nodes", "inserted", totalInserted, "key", common.Bytes2Hex(key))
// default:
// }
// })

rootHash := node.Commitment().Bytes()
encodedNode, err = node.Serialize()
node.(*verkle.InternalNode).Flush(func(path []byte, node verkle.VerkleNode) {
node.Commit()
s, err := node.Serialize()
if err != nil {
return
panic(err)
}
err = collector.Collect(rootHash[:], encodedNode)
totalInserted++
select {
case <-logInterval.C:
logger.Info("Flushing Verkle nodes", "inserted", totalInserted, "key", common.Bytes2Hex(key))
default:
if err := collector.Collect(path, s); err != nil {
panic(err)
}
})

return err
}

Expand Down Expand Up @@ -100,10 +123,10 @@ func (v *VerkleTreeWriter) UpdateAccount(versionKey []byte, codeSize uint64, isC
copy(nonceKey[:], versionKey[:31])
copy(balanceKey[:], versionKey[:31])
copy(codeSizeKey[:], versionKey[:31])
codeHashKey[31] = vtree.CodeKeccakLeafKey
nonceKey[31] = vtree.NonceLeafKey
balanceKey[31] = vtree.BalanceLeafKey
codeSizeKey[31] = vtree.CodeSizeLeafKey
codeHashKey[31] = vkutils.CodeKeccakLeafKey
nonceKey[31] = vkutils.NonceLeafKey
balanceKey[31] = vkutils.BalanceLeafKey
codeSizeKey[31] = vkutils.CodeSizeLeafKey
// Process values
int256ToVerkleFormat(&acc.Balance, balance[:])
binary.LittleEndian.PutUint64(nonce[:], acc.Nonce)
Expand Down Expand Up @@ -139,10 +162,10 @@ func (v *VerkleTreeWriter) DeleteAccount(versionKey []byte, isContract bool) err
copy(nonceKey[:], versionKey[:31])
copy(balanceKey[:], versionKey[:31])
copy(codeSizeKey[:], versionKey[:31])
codeHashKey[31] = vtree.CodeKeccakLeafKey
nonceKey[31] = vtree.NonceLeafKey
balanceKey[31] = vtree.BalanceLeafKey
codeSizeKey[31] = vtree.CodeSizeLeafKey
codeHashKey[31] = vkutils.CodeKeccakLeafKey
nonceKey[31] = vkutils.NonceLeafKey
balanceKey[31] = vkutils.BalanceLeafKey
codeSizeKey[31] = vkutils.CodeSizeLeafKey
// Insert in the tree
if err := v.collector.Collect(versionKey, []byte{0}); err != nil {
return err
Expand Down Expand Up @@ -194,31 +217,32 @@ func (v *VerkleTreeWriter) CommitVerkleTreeFromScratch() (libcommon.Hash, error)
root := verkle.New()

logInterval := time.NewTicker(30 * time.Second)
if err := v.collector.Load(v.db, kv.VerkleTrie, func(k []byte, val []byte, _ etl.CurrentTableReader, next etl.LoadNextFunc) error {
if len(val) == 0 {
return next(k, nil, nil)
}
if err := root.InsertOrdered(libcommon.CopyBytes(k), libcommon.CopyBytes(val), func(node verkle.VerkleNode) {
rootHash := node.Commitment().Bytes()
encodedNode, err := node.Serialize()
if err != nil {
panic(err)
}
if err := verkleCollector.Collect(rootHash[:], encodedNode); err != nil {
panic(err)
}
select {
case <-logInterval.C:
v.logger.Info("[Verkle] Assembling Verkle Tree", "key", common.Bytes2Hex(k))
default:
}
}); err != nil {
return err
}
return next(k, nil, nil)
}, etl.TransformArgs{Quit: context.Background().Done()}); err != nil {
return libcommon.Hash{}, err
}
// if err := v.collector.Load(v.db, kv.VerkleTrie, func(k []byte, val []byte, _ etl.CurrentTableReader, next etl.LoadNextFunc) error {
// if len(val) == 0 {
// return next(k, nil, nil)
// }
// if err := root.Insert(libcommon.CopyBytes(k), libcommon.CopyBytes(val),
// func(node verkle.VerkleNode) {
// rootHash := node.Commitment().Bytes()
// encodedNode, err := node.Serialize()
// if err != nil {
// panic(err)
// }
// if err := verkleCollector.Collect(rootHash[:], encodedNode); err != nil {
// panic(err)
// }
// select {
// case <-logInterval.C:
// v.logger.Info("[Verkle] Assembling Verkle Tree", "key", common.Bytes2Hex(k))
// default:
// }
// }); err != nil {
// return err
// }
// return next(k, nil, nil)
// }, etl.TransformArgs{Quit: context.Background().Done()}); err != nil {
// return libcommon.Hash{}, err
// }

// Flush the rest all at once
if err := collectVerkleNode(v.collector, root, logInterval, nil, v.logger); err != nil {
Expand Down
20 changes: 10 additions & 10 deletions cmd/verkle/verkletrie/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
libcommon "github.com/ledgerwatch/erigon-lib/common"

"github.com/ledgerwatch/erigon/core/types/accounts"
"github.com/ledgerwatch/erigon/turbo/trie/vtree"
"github.com/ledgerwatch/erigon/turbo/trie/vkutils"
)

type regeneratePedersenAccountsJob struct {
Expand Down Expand Up @@ -83,7 +83,7 @@ func pedersenAccountWorker(ctx context.Context, logPrefix string, in chan *regen

// prevent sending to close channel
out <- &regeneratePedersenAccountsOut{
versionHash: libcommon.BytesToHash(vtree.GetTreeKeyVersion(job.address[:])),
versionHash: libcommon.BytesToHash(vkutils.GetTreeKeyVersion(job.address[:])),
account: job.account,
address: job.address,
codeSize: job.codeSize,
Expand All @@ -107,7 +107,7 @@ func pedersenStorageWorker(ctx context.Context, logPrefix string, in, out chan *
return
}
out <- &regeneratePedersenStorageJob{
storageVerkleKey: libcommon.BytesToHash(vtree.GetTreeKeyStorageSlot(job.address[:], job.storageKey)),
storageVerkleKey: libcommon.BytesToHash(vkutils.GetTreeKeyStorageSlot(job.address[:], job.storageKey)),
storageKey: job.storageKey,
address: job.address,
storageValue: job.storageValue,
Expand Down Expand Up @@ -142,15 +142,15 @@ func pedersenCodeWorker(ctx context.Context, logPrefix string, in chan *regenera
}
}
// Chunkify contract code and build keys for each chunks and insert them in the tree
chunkedCode := vtree.ChunkifyCode(job.code)
chunkedCode := vkutils.ChunkifyCode(job.code)
offset := byte(0)
offsetOverflow := false
currentKey := vtree.GetTreeKeyCodeChunk(job.address[:], uint256.NewInt(0))
currentKey := vkutils.GetTreeKeyCodeChunk(job.address[:], uint256.NewInt(0))
// Write code chunks
for i := 0; i < len(chunkedCode); i += 32 {
chunks = append(chunks, libcommon.CopyBytes(chunkedCode[i:i+32]))
if currentKey[31]+offset < currentKey[31] || offsetOverflow {
currentKey = vtree.GetTreeKeyCodeChunk(job.address[:], uint256.NewInt(uint64(i)/32))
currentKey = vkutils.GetTreeKeyCodeChunk(job.address[:], uint256.NewInt(uint64(i)/32))
chunkKeys = append(chunkKeys, libcommon.CopyBytes(currentKey))
offset = 1
offsetOverflow = false
Expand Down Expand Up @@ -187,7 +187,7 @@ func incrementalAccountWorker(ctx context.Context, logPrefix string, in chan *re
case <-ctx.Done():
return
}
versionKey := libcommon.BytesToHash(vtree.GetTreeKeyVersion(job.address[:]))
versionKey := libcommon.BytesToHash(vkutils.GetTreeKeyVersion(job.address[:]))
if job.absentInState {
out <- &regenerateIncrementalPedersenAccountsOut{
versionHash: versionKey[:],
Expand All @@ -200,16 +200,16 @@ func incrementalAccountWorker(ctx context.Context, logPrefix string, in chan *re
var chunks [][]byte
var chunkKeys [][]byte
// Chunkify contract code and build keys for each chunks and insert them in the tree
chunkedCode := vtree.ChunkifyCode(job.code)
chunkedCode := vkutils.ChunkifyCode(job.code)
offset := byte(0)
offsetOverflow := false
currentKey := vtree.GetTreeKeyCodeChunk(job.address[:], uint256.NewInt(0))
currentKey := vkutils.GetTreeKeyCodeChunk(job.address[:], uint256.NewInt(0))
// Write code chunks
for i := 0; i < len(chunkedCode); i += 32 {
chunks = append(chunks, libcommon.CopyBytes(chunkedCode[i:i+32]))
codeKey := libcommon.CopyBytes(currentKey)
if currentKey[31]+offset < currentKey[31] || offsetOverflow {
currentKey = vtree.GetTreeKeyCodeChunk(job.address[:], uint256.NewInt(uint64(i)/32))
currentKey = vkutils.GetTreeKeyCodeChunk(job.address[:], uint256.NewInt(uint64(i)/32))
chunkKeys = append(chunkKeys, codeKey)
offset = 1
offsetOverflow = false
Expand Down
3 changes: 2 additions & 1 deletion common/paths/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ func DataDirForNetwork(datadir string, network string) string {
return networkDataDirCheckingLegacy(datadir, "gnosis")
case networkname.ChiadoChainName:
return networkDataDirCheckingLegacy(datadir, "chiado")

case networkname.VerkleGenDevnet2:
return networkDataDirCheckingLegacy(datadir, "verkle-gen-devnet2")
default:
return datadir
}
Expand Down
2 changes: 1 addition & 1 deletion consensus/aura/aura_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
func TestEmptyBlock(t *testing.T) {
require := require.New(t)
genesis := core.GnosisGenesisBlock()
genesisBlock, _, err := core.GenesisToBlock(genesis, "")
genesisBlock, _, err := core.GenesisToBlock(genesis, "", nil)
require.NoError(err)

genesis.Config.TerminalTotalDifficultyPassed = false
Expand Down
7 changes: 7 additions & 0 deletions consensus/ethash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/ledgerwatch/erigon-lib/chain"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon/consensus/ethash/ethashcfg"
"github.com/ledgerwatch/erigon/turbo/trie/vkutils"
"github.com/ledgerwatch/log/v3"
"golang.org/x/crypto/sha3"

Expand Down Expand Up @@ -668,5 +669,11 @@ func accumulateRewards(config *chain.Config, state *state.IntraBlockState, heade
state.AddBalance(uncle.Coinbase, &uncleRewards[i])
}
}
if config.IsPrague(header.Time) {
state.Witness().TouchAddressOnReadAndComputeGas(header.Coinbase.Bytes(), uint256.Int{}, vkutils.BalanceLeafKey)
state.Witness().TouchAddressOnReadAndComputeGas(header.Coinbase.Bytes(), uint256.Int{}, vkutils.VersionLeafKey)
state.Witness().TouchAddressOnReadAndComputeGas(header.Coinbase.Bytes(), uint256.Int{}, vkutils.NonceLeafKey)
state.Witness().TouchAddressOnReadAndComputeGas(header.Coinbase.Bytes(), uint256.Int{}, vkutils.CodeKeccakLeafKey)
}
state.AddBalance(header.Coinbase, &minerReward)
}
Loading