mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-25 13:07:17 +00:00
move (#2910)
This commit is contained in:
parent
686721b6c6
commit
1a45f26a7c
@ -20,13 +20,13 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
|
||||||
|
"github.com/google/btree"
|
||||||
"github.com/holiman/uint256"
|
"github.com/holiman/uint256"
|
||||||
"github.com/ledgerwatch/erigon-lib/kv"
|
"github.com/ledgerwatch/erigon-lib/kv"
|
||||||
"github.com/ledgerwatch/erigon/common"
|
"github.com/ledgerwatch/erigon/common"
|
||||||
"github.com/ledgerwatch/erigon/common/dbutils"
|
"github.com/ledgerwatch/erigon/common/dbutils"
|
||||||
"github.com/ledgerwatch/erigon/core/types/accounts"
|
"github.com/ledgerwatch/erigon/core/types/accounts"
|
||||||
"github.com/ledgerwatch/log/v3"
|
"github.com/ledgerwatch/log/v3"
|
||||||
"github.com/petar/GoLLRB/llrb"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type storageItem struct {
|
type storageItem struct {
|
||||||
@ -34,7 +34,7 @@ type storageItem struct {
|
|||||||
value uint256.Int
|
value uint256.Int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *storageItem) Less(b llrb.Item) bool {
|
func (a *storageItem) Less(b btree.Item) bool {
|
||||||
bi := b.(*storageItem)
|
bi := b.(*storageItem)
|
||||||
return bytes.Compare(a.key[:], bi.key[:]) < 0
|
return bytes.Compare(a.key[:], bi.key[:]) < 0
|
||||||
}
|
}
|
||||||
@ -44,7 +44,7 @@ type PlainState struct {
|
|||||||
accChangesC, storageChangesC kv.CursorDupSort
|
accChangesC, storageChangesC kv.CursorDupSort
|
||||||
tx kv.Tx
|
tx kv.Tx
|
||||||
blockNr uint64
|
blockNr uint64
|
||||||
storage map[common.Address]*llrb.LLRB
|
storage map[common.Address]*btree.BTree
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPlainState(tx kv.Tx, blockNr uint64) *PlainState {
|
func NewPlainState(tx kv.Tx, blockNr uint64) *PlainState {
|
||||||
@ -56,7 +56,7 @@ func NewPlainState(tx kv.Tx, blockNr uint64) *PlainState {
|
|||||||
return &PlainState{
|
return &PlainState{
|
||||||
tx: tx,
|
tx: tx,
|
||||||
blockNr: blockNr,
|
blockNr: blockNr,
|
||||||
storage: make(map[common.Address]*llrb.LLRB),
|
storage: make(map[common.Address]*btree.BTree),
|
||||||
accHistoryC: c1, storageHistoryC: c2, accChangesC: c3, storageChangesC: c4,
|
accHistoryC: c1, storageHistoryC: c2, accChangesC: c3, storageChangesC: c4,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -70,7 +70,7 @@ func (s *PlainState) GetBlockNr() uint64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *PlainState) ForEachStorage(addr common.Address, startLocation common.Hash, cb func(key, seckey common.Hash, value uint256.Int) bool, maxResults int) error {
|
func (s *PlainState) ForEachStorage(addr common.Address, startLocation common.Hash, cb func(key, seckey common.Hash, value uint256.Int) bool, maxResults int) error {
|
||||||
st := llrb.New()
|
st := btree.New(16)
|
||||||
var k [common.AddressLength + common.IncarnationLength + common.HashLength]byte
|
var k [common.AddressLength + common.IncarnationLength + common.HashLength]byte
|
||||||
copy(k[:], addr[:])
|
copy(k[:], addr[:])
|
||||||
accData, err := GetAsOf(s.tx, s.accHistoryC, s.accChangesC, false /* storage */, addr[:], s.blockNr+1)
|
accData, err := GetAsOf(s.tx, s.accHistoryC, s.accChangesC, false /* storage */, addr[:], s.blockNr+1)
|
||||||
@ -88,7 +88,7 @@ func (s *PlainState) ForEachStorage(addr common.Address, startLocation common.Ha
|
|||||||
overrideCounter := 0
|
overrideCounter := 0
|
||||||
min := &storageItem{key: startLocation}
|
min := &storageItem{key: startLocation}
|
||||||
if t, ok := s.storage[addr]; ok {
|
if t, ok := s.storage[addr]; ok {
|
||||||
t.AscendGreaterOrEqual(min, func(i llrb.Item) bool {
|
t.AscendGreaterOrEqual(min, func(i btree.Item) bool {
|
||||||
item := i.(*storageItem)
|
item := i.(*storageItem)
|
||||||
st.ReplaceOrInsert(item)
|
st.ReplaceOrInsert(item)
|
||||||
if !item.value.IsZero() {
|
if !item.value.IsZero() {
|
||||||
@ -120,7 +120,7 @@ func (s *PlainState) ForEachStorage(addr common.Address, startLocation common.Ha
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
si.value.SetBytes(vs)
|
si.value.SetBytes(vs)
|
||||||
st.InsertNoReplace(&si)
|
st.ReplaceOrInsert(&si)
|
||||||
if bytes.Compare(kLoc, lastKey[:]) > 0 {
|
if bytes.Compare(kLoc, lastKey[:]) > 0 {
|
||||||
// Beyond overrides
|
// Beyond overrides
|
||||||
return st.Len() < maxResults+numDeletes, nil
|
return st.Len() < maxResults+numDeletes, nil
|
||||||
@ -132,7 +132,7 @@ func (s *PlainState) ForEachStorage(addr common.Address, startLocation common.Ha
|
|||||||
}
|
}
|
||||||
results := 0
|
results := 0
|
||||||
var innerErr error
|
var innerErr error
|
||||||
st.AscendGreaterOrEqual(min, func(i llrb.Item) bool {
|
st.AscendGreaterOrEqual(min, func(i btree.Item) bool {
|
||||||
item := i.(*storageItem)
|
item := i.(*storageItem)
|
||||||
if !item.value.IsZero() {
|
if !item.value.IsZero() {
|
||||||
// Skip if value == 0
|
// Skip if value == 0
|
||||||
@ -230,7 +230,7 @@ func (s *PlainState) UpdateAccountCode(address common.Address, incarnation uint6
|
|||||||
func (s *PlainState) WriteAccountStorage(address common.Address, incarnation uint64, key *common.Hash, original, value *uint256.Int) error {
|
func (s *PlainState) WriteAccountStorage(address common.Address, incarnation uint64, key *common.Hash, original, value *uint256.Int) error {
|
||||||
t, ok := s.storage[address]
|
t, ok := s.storage[address]
|
||||||
if !ok {
|
if !ok {
|
||||||
t = llrb.New()
|
t = btree.New(16)
|
||||||
s.storage[address] = t
|
s.storage[address] = t
|
||||||
}
|
}
|
||||||
h := common.NewHasher()
|
h := common.NewHasher()
|
||||||
|
1
go.mod
1
go.mod
@ -41,7 +41,6 @@ require (
|
|||||||
github.com/ledgerwatch/secp256k1 v0.0.0-20210626115225-cd5cd00ed72d
|
github.com/ledgerwatch/secp256k1 v0.0.0-20210626115225-cd5cd00ed72d
|
||||||
github.com/logrusorgru/aurora/v3 v3.0.0
|
github.com/logrusorgru/aurora/v3 v3.0.0
|
||||||
github.com/pelletier/go-toml v1.9.4
|
github.com/pelletier/go-toml v1.9.4
|
||||||
github.com/petar/GoLLRB v0.0.0-20190514000832-33fb24c13b99
|
|
||||||
github.com/quasilyte/go-ruleguard/dsl v0.3.6
|
github.com/quasilyte/go-ruleguard/dsl v0.3.6
|
||||||
github.com/rs/cors v1.8.0
|
github.com/rs/cors v1.8.0
|
||||||
github.com/shirou/gopsutil/v3 v3.21.9
|
github.com/shirou/gopsutil/v3 v3.21.9
|
||||||
|
2
go.sum
2
go.sum
@ -582,8 +582,6 @@ github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FI
|
|||||||
github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
|
github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
|
||||||
github.com/pelletier/go-toml v1.9.4 h1:tjENF6MfZAg8e4ZmZTeWaWiT2vXtsoO6+iuOjFhECwM=
|
github.com/pelletier/go-toml v1.9.4 h1:tjENF6MfZAg8e4ZmZTeWaWiT2vXtsoO6+iuOjFhECwM=
|
||||||
github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
|
github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
|
||||||
github.com/petar/GoLLRB v0.0.0-20190514000832-33fb24c13b99 h1:KcEvVBAvyHkUdFAygKAzwB6LAcZ6LS32WHmRD2VyXMI=
|
|
||||||
github.com/petar/GoLLRB v0.0.0-20190514000832-33fb24c13b99/go.mod h1:HUpKUBZnpzkdx0kD/+Yfuft+uD3zHGtXF/XJB14TUr4=
|
|
||||||
github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
|
github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
|
||||||
github.com/philhofer/fwd v1.1.1/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
|
github.com/philhofer/fwd v1.1.1/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
|
||||||
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
|
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
|
||||||
|
Loading…
Reference in New Issue
Block a user