erigon-pulse/params/eip_ctx.go
ledgerwatch 12cde41772
Aleut support (Eip1559) (#1704)
* Where I am at

* Refactoring of transaction types

* More refactoring

* Use Homested signer in rpc daemon

* Unified signer

* Continue unified signer

* A bit more

* Fixes and down the rabbit hole...

* More tx pool fixes

* More refactoring fixes

* More fixes'

* more fixes

* More fixes

* More compile fixes

* More RLP hand-writing

* Finish RLP encoding/decoding of transactions

* Fixes to header encoding, start on protocol packets

* Transaction decoding

* Use DecodeTransaction function

* Decoding BlockBodyPacket

* Encode and decode for pool txs

* Start fixing tests

* Introduce SigningHash

* Fixes to SignHash

* RLP encoding fixes

* Fixes for encoding/decoding

* More test fixes

* Fix more tests

* More test fixes

* More test fixes

* Fix core tests

* More fixes for signer

* Fix for tx

* Fixes to string encoding/size

* Fix eip2930 test

* Fix rest of ./tests

* More fixes

* Fix compilation

* More test fixes

* More test fixes

* Test fixes

* More fixes

* Reuse EncodingSize in EncodeRLP for accessList

* Rearrange things in dynamic fee tx

* Add MarshalBinary

* More fixes

* Make V,R,S non-pointers

* More NPE fixes

* More fixes

* Receipt fixes

* Fix core/types

* Fix ./eth

* More compile fixes for tests

* More test fixes

* More test fixes

* Try to see lint errors better

* Try to see lint errors better

* Fix lint

* Debugging eip1559 test

* Fix TestEIP1559Transition test

* Fix NewBlockPacket encoding/decoding

* Fix calculation of TxHash

* Fix perf problem with senders

* Update aleut config values

* Try adding static peers

* Add staticpeers to defaul flags

* Change aleut networkID

* Fix test

Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
2021-04-22 18:11:37 +01:00

162 lines
3.7 KiB
Go

package params
import (
"context"
"math/big"
)
type configKey int
const (
IsHomesteadEnabled configKey = iota
IsEIP150Enabled
IsEIP155Enabled
IsEIP158Enabled
IsByzantiumEnabled
IsConstantinopleEnabled
IsPetersburgEnabled
BlockNumber
NoHistory
WithHistoryHighest
)
func (c *ChainConfig) WithEIPsFlags(ctx context.Context, blockNum uint64) 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, IsByzantiumEnabled, c.IsByzantium(blockNum))
ctx = context.WithValue(ctx, IsConstantinopleEnabled, c.IsConstantinople(blockNum))
ctx = context.WithValue(ctx, IsPetersburgEnabled, c.IsPetersburg(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)
}
}