mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-03 09:37:38 +00:00
ce96cf75b2
* #remove debug prints * remove storage-mode="i" * minnet re-execute hack with checkpoints * minnet re-execute hack with checkpoints * rollback to master setup * mainnet re-exec hack * rollback some changes * v0 of "push down" functionality * move all logic to own functions * handle case when re-created account already has some storage * clear path for storage * try to rely on tree structure (but maybe need to rely on DB because can be intra-block re-creations of account) * fix some bugs with indexes, moving to tests * tests added * make linter happy * make linter happy * simplify logic * adjust comparison of keys with and without incarnation * test for keyIsBefore * test for keyIsBefore * better nibbles alignment * better nibbles alignment * cleanup * continue work on tests * simplify test * check tombstone existence before pushing it down. * put tombstone only when account deleted, not created * put tombstone only when account has storage * make linter happy * test for storage resolver * make fixedbytes work without incarnation * fix panic on short keys * use special comparison only when working with keys from cache * add blockNr for better tracing * fix: incorrect tombstone check * fix: incorrect tombstone check * trigger ci * hack for problem block * more test-cases * add test case for too long keys * speedup cached resolver by removing bucket creation transaction * remove parent type check in pruning, remove unused copy from mutation.put * dump resolving info on fail * dump resolving info on fail * set tombstone everytime for now to check if it will help * on unload: check parent type, not type of node * fix wrong order of checking node type * fix wrong order of checking node type * rebase to new master * make linter happy * rebase to new master * place tombstone only if acc has storage * rebase master * rebase master * rebase master * rebase master Co-authored-by: alex.sharov <alex.sharov@lazada.com>
166 lines
3.8 KiB
Go
166 lines
3.8 KiB
Go
package params
|
|
|
|
import (
|
|
"context"
|
|
"math/big"
|
|
)
|
|
|
|
type configKey int
|
|
|
|
const (
|
|
IsHomesteadEnabled configKey = iota
|
|
IsEIP150Enabled
|
|
IsEIP155Enabled
|
|
IsEIP158Enabled
|
|
IsEIP2027Enabled
|
|
IsByzantiumEnabled
|
|
IsConstantinopleEnabled
|
|
IsPetersburgEnabled
|
|
IsEWASM
|
|
BlockNumber
|
|
NoHistory
|
|
WithHistoryHighest
|
|
)
|
|
|
|
func (c *ChainConfig) WithEIPsFlags(ctx context.Context, blockNum *big.Int) context.Context {
|
|
ctx = context.WithValue(ctx, IsHomesteadEnabled, c.IsHomestead(blockNum))
|
|
ctx = context.WithValue(ctx, IsEIP150Enabled, c.IsEIP150(blockNum))
|
|
ctx = context.WithValue(ctx, IsEIP155Enabled, c.IsEIP155(blockNum))
|
|
ctx = context.WithValue(ctx, IsEIP158Enabled, c.IsEIP158(blockNum))
|
|
ctx = context.WithValue(ctx, IsEIP2027Enabled, c.IsEIP2027(blockNum))
|
|
ctx = context.WithValue(ctx, IsByzantiumEnabled, c.IsByzantium(blockNum))
|
|
ctx = context.WithValue(ctx, IsConstantinopleEnabled, c.IsConstantinople(blockNum))
|
|
ctx = context.WithValue(ctx, IsPetersburgEnabled, c.IsPetersburg(blockNum))
|
|
ctx = context.WithValue(ctx, IsEWASM, c.IsEWASM(blockNum))
|
|
ctx = context.WithValue(ctx, BlockNumber, blockNum)
|
|
return ctx
|
|
}
|
|
|
|
func WithNoHistory(ctx context.Context, defaultValue bool, f noHistFunc) context.Context {
|
|
return context.WithValue(ctx, NoHistory, getIsNoHistory(defaultValue, f))
|
|
}
|
|
|
|
func GetForkFlag(ctx context.Context, name configKey) bool {
|
|
b := ctx.Value(name)
|
|
if b == nil {
|
|
return false
|
|
}
|
|
if valB, ok := b.(bool); ok {
|
|
return valB
|
|
}
|
|
return false
|
|
}
|
|
|
|
func GetBlockNumber(ctx context.Context) *big.Int {
|
|
b := ctx.Value(BlockNumber)
|
|
if b == nil {
|
|
return nil
|
|
}
|
|
if valB, ok := b.(*big.Int); ok {
|
|
return valB
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func GetNoHistoryByBlock(ctx context.Context, currentBlock *big.Int) (context.Context, bool) {
|
|
if currentBlock == nil {
|
|
return ctx, false
|
|
}
|
|
|
|
key := getNoHistoryByBlock(currentBlock)
|
|
v, ok := getNoHistoryByKey(ctx, key)
|
|
if ok {
|
|
if !v {
|
|
ctx = updateHighestWithHistory(ctx, currentBlock)
|
|
}
|
|
return ctx, v
|
|
}
|
|
|
|
return withNoHistory(ctx, currentBlock, key)
|
|
}
|
|
|
|
func withNoHistory(ctx context.Context, currentBlock *big.Int, key configKey) (context.Context, bool) {
|
|
v := getNoHistory(ctx, currentBlock)
|
|
ctx = context.WithValue(ctx, key, v)
|
|
if !v {
|
|
ctx = updateHighestWithHistory(ctx, currentBlock)
|
|
}
|
|
|
|
return ctx, v
|
|
}
|
|
|
|
func updateHighestWithHistory(ctx context.Context, currentBlock *big.Int) context.Context {
|
|
highestWithHistory := getWithHistoryHighest(ctx)
|
|
var currentIsLower bool
|
|
if highestWithHistory != nil {
|
|
currentIsLower = currentBlock.Cmp(highestWithHistory) < 0
|
|
}
|
|
if !currentIsLower {
|
|
ctx = setWithHistoryHighestByBlock(ctx, currentBlock)
|
|
}
|
|
return ctx
|
|
}
|
|
|
|
func getNoHistory(ctx context.Context, currentBlock *big.Int) bool {
|
|
v := ctx.Value(NoHistory)
|
|
if v == nil {
|
|
return false
|
|
}
|
|
if val, ok := v.(noHistFunc); ok {
|
|
return val(currentBlock)
|
|
}
|
|
return false
|
|
}
|
|
|
|
func getWithHistoryHighest(ctx context.Context) *big.Int {
|
|
v := ctx.Value(WithHistoryHighest)
|
|
if v == nil {
|
|
return nil
|
|
}
|
|
if val, ok := v.(*big.Int); ok {
|
|
return val
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func setWithHistoryHighestByBlock(ctx context.Context, block *big.Int) context.Context {
|
|
return context.WithValue(ctx, WithHistoryHighest, block)
|
|
}
|
|
|
|
func getNoHistoryByKey(ctx context.Context, key configKey) (bool, bool) {
|
|
if key < 0 {
|
|
return false, false
|
|
}
|
|
v := ctx.Value(key)
|
|
if v == nil {
|
|
return false, false
|
|
}
|
|
if val, ok := v.(bool); ok {
|
|
return val, true
|
|
}
|
|
return false, false
|
|
}
|
|
|
|
func getNoHistoryByBlock(block *big.Int) configKey {
|
|
if block == nil {
|
|
return configKey(-1)
|
|
}
|
|
return configKey(block.Uint64() + 1000)
|
|
}
|
|
|
|
func GetNoHistory(ctx context.Context) (context.Context, bool) {
|
|
return GetNoHistoryByBlock(ctx, GetBlockNumber(ctx))
|
|
}
|
|
|
|
type noHistFunc func(currentBlock *big.Int) bool
|
|
|
|
func getIsNoHistory(defaultValue bool, f noHistFunc) noHistFunc {
|
|
return func(currentBlock *big.Int) bool {
|
|
if f == nil {
|
|
return defaultValue
|
|
}
|
|
|
|
return f(currentBlock)
|
|
}
|
|
}
|