mirror of
https://github.com/luxfi/geth.git
synced 2026-07-27 01:59:25 +00:00
feat: add Lux extensions for coreth compatibility
- Add PrecompileEnvironment interface for stateful precompiles - Expand stateconf package with StateDBStateOption configuration - Fix badgerdb iterator first-item handling - Add Reader type alias in triedb/database for coreth - Add NilXxx types in metrics for prometheus gatherer
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
// Copyright (C) 2020-2025, Lux Industries Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
package vm
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
"github.com/luxfi/geth/common"
|
||||
"github.com/luxfi/geth/core/types"
|
||||
"github.com/luxfi/geth/params"
|
||||
)
|
||||
|
||||
// PrecompileEnvironment is the interface for precompile execution environment.
|
||||
// This is a Lux extension for stateful precompiles that need access to
|
||||
// the execution context.
|
||||
type PrecompileEnvironment interface {
|
||||
// BlockHeader returns the block header
|
||||
BlockHeader() (*types.Header, error)
|
||||
// Rules returns the chain rules
|
||||
Rules() params.Rules
|
||||
// BlockNumber returns the current block number
|
||||
BlockNumber() *big.Int
|
||||
// BlockTime returns the current block timestamp
|
||||
BlockTime() uint64
|
||||
// Addresses returns the caller and contract addresses
|
||||
Addresses() PrecompileAddresses
|
||||
// ReadOnly returns whether the environment is read-only
|
||||
ReadOnly() bool
|
||||
// ChainConfig returns the chain config
|
||||
ChainConfig() *params.ChainConfig
|
||||
// StateDB returns the state database
|
||||
StateDB() StateDB
|
||||
// ReadOnlyState returns a read-only state view
|
||||
ReadOnlyState() StateDB
|
||||
// UseGas deducts gas from the available gas
|
||||
UseGas(gas uint64) bool
|
||||
// Gas returns the available gas
|
||||
Gas() uint64
|
||||
// Call executes a call to another contract
|
||||
Call(addr common.Address, input []byte, gas uint64, value *big.Int, opts ...CallOption) ([]byte, uint64, error)
|
||||
}
|
||||
|
||||
// CallOption is an option for Call
|
||||
type CallOption func(*CallConfig)
|
||||
|
||||
// CallConfig holds call configuration
|
||||
type CallConfig struct {
|
||||
ProxyCaller bool
|
||||
}
|
||||
|
||||
// WithUNSAFECallerAddressProxying returns an option to proxy caller address
|
||||
func WithUNSAFECallerAddressProxying() CallOption {
|
||||
return func(c *CallConfig) {
|
||||
c.ProxyCaller = true
|
||||
}
|
||||
}
|
||||
|
||||
// PrecompileAddresses holds the caller and self addresses for a precompile call
|
||||
type PrecompileAddresses struct {
|
||||
Caller common.Address
|
||||
Self common.Address
|
||||
}
|
||||
@@ -118,8 +118,9 @@ func (d *Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator {
|
||||
}
|
||||
|
||||
return &iterator{
|
||||
iter: iter,
|
||||
txn: txn,
|
||||
iter: iter,
|
||||
txn: txn,
|
||||
first: true, // First call to Next() should check Valid() without advancing
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,14 +187,22 @@ func (b *batch) Replay(w ethdb.KeyValueWriter) error {
|
||||
|
||||
// iterator implements ethdb.Iterator
|
||||
type iterator struct {
|
||||
iter *badger.Iterator
|
||||
txn *badger.Txn
|
||||
iter *badger.Iterator
|
||||
txn *badger.Txn
|
||||
first bool // true if we haven't returned the first item yet
|
||||
}
|
||||
|
||||
func (i *iterator) Next() bool {
|
||||
if i.iter == nil {
|
||||
return false
|
||||
}
|
||||
// On first call after NewIterator, the iterator is already positioned
|
||||
// at the first item (via Rewind/Seek), so just check Valid()
|
||||
if i.first {
|
||||
i.first = false
|
||||
return i.iter.Valid()
|
||||
}
|
||||
// On subsequent calls, advance and check
|
||||
i.iter.Next()
|
||||
return i.iter.Valid()
|
||||
}
|
||||
|
||||
@@ -1,4 +1,112 @@
|
||||
// Copyright (C) 2020-2025, Lux Industries Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
// Package stateconf provides configuration types for state database operations.
|
||||
// This is a Lux extension for configurable state operations.
|
||||
package stateconf
|
||||
|
||||
// Stub for stateconf
|
||||
type Config struct{}
|
||||
import "github.com/luxfi/geth/common"
|
||||
|
||||
// StateDBStateOption is an option for state database operations
|
||||
type StateDBStateOption func(*StateDBStateConfig)
|
||||
|
||||
// StateDBStateConfig holds configuration for state DB operations
|
||||
type StateDBStateConfig struct {
|
||||
SkipKeyTransformation bool
|
||||
}
|
||||
|
||||
// SkipStateKeyTransformation returns an option to skip state key transformation
|
||||
func SkipStateKeyTransformation() StateDBStateOption {
|
||||
return func(c *StateDBStateConfig) {
|
||||
c.SkipKeyTransformation = true
|
||||
}
|
||||
}
|
||||
|
||||
// ApplyStateDBOptions applies the given options to a config
|
||||
func ApplyStateDBOptions(opts ...StateDBStateOption) *StateDBStateConfig {
|
||||
config := &StateDBStateConfig{}
|
||||
for _, opt := range opts {
|
||||
opt(config)
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
// TrieDBUpdateOption is an option for trie database updates
|
||||
type TrieDBUpdateOption func(*TrieDBUpdateConfig)
|
||||
|
||||
// TrieDBUpdateConfig holds configuration for trie DB updates
|
||||
type TrieDBUpdateConfig struct {
|
||||
ParentHash common.Hash
|
||||
BlockHash common.Hash
|
||||
}
|
||||
|
||||
// WithTrieDBUpdatePayload returns an option with parent and block hashes
|
||||
func WithTrieDBUpdatePayload(parentHash, blockHash common.Hash) TrieDBUpdateOption {
|
||||
return func(c *TrieDBUpdateConfig) {
|
||||
c.ParentHash = parentHash
|
||||
c.BlockHash = blockHash
|
||||
}
|
||||
}
|
||||
|
||||
// ExtractTrieDBUpdatePayload extracts the payload from options
|
||||
func ExtractTrieDBUpdatePayload(opts ...TrieDBUpdateOption) (common.Hash, common.Hash) {
|
||||
config := &TrieDBUpdateConfig{}
|
||||
for _, opt := range opts {
|
||||
opt(config)
|
||||
}
|
||||
return config.ParentHash, config.BlockHash
|
||||
}
|
||||
|
||||
// SnapshotUpdateOption is an option for snapshot updates
|
||||
type SnapshotUpdateOption func(*SnapshotUpdateConfig)
|
||||
|
||||
// SnapshotUpdateConfig holds configuration for snapshot updates
|
||||
type SnapshotUpdateConfig struct {
|
||||
Payload interface{}
|
||||
}
|
||||
|
||||
// WithSnapshotUpdatePayload returns an option with the given payload
|
||||
func WithSnapshotUpdatePayload(payload interface{}) SnapshotUpdateOption {
|
||||
return func(c *SnapshotUpdateConfig) {
|
||||
c.Payload = payload
|
||||
}
|
||||
}
|
||||
|
||||
// ExtractSnapshotUpdatePayload extracts the payload from an option
|
||||
func ExtractSnapshotUpdatePayload(opt SnapshotUpdateOption) interface{} {
|
||||
config := &SnapshotUpdateConfig{}
|
||||
opt(config)
|
||||
return config.Payload
|
||||
}
|
||||
|
||||
// CommitOption is an option for state commit operations
|
||||
type CommitOption func(*CommitConfig)
|
||||
|
||||
// CommitConfig holds configuration for commit operations
|
||||
type CommitConfig struct {
|
||||
TrieDBUpdateOpts []TrieDBUpdateOption
|
||||
SnapshotUpdateOpts []SnapshotUpdateOption
|
||||
}
|
||||
|
||||
// WithTrieDBUpdateOpts returns a commit option with trie DB update options
|
||||
func WithTrieDBUpdateOpts(opts ...TrieDBUpdateOption) CommitOption {
|
||||
return func(c *CommitConfig) {
|
||||
c.TrieDBUpdateOpts = append(c.TrieDBUpdateOpts, opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// WithSnapshotUpdateOpts returns a commit option with snapshot update options
|
||||
func WithSnapshotUpdateOpts(opts ...SnapshotUpdateOption) CommitOption {
|
||||
return func(c *CommitConfig) {
|
||||
c.SnapshotUpdateOpts = append(c.SnapshotUpdateOpts, opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ApplyCommitOptions applies commit options and returns config
|
||||
func ApplyCommitOptions(opts ...CommitOption) *CommitConfig {
|
||||
config := &CommitConfig{}
|
||||
for _, opt := range opts {
|
||||
opt(config)
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
package metrics
|
||||
|
||||
// Nil types are empty structs used to detect disabled/nil metrics
|
||||
// in type switches (used by prometheus gatherer)
|
||||
|
||||
type NilCounter struct{}
|
||||
type NilCounterFloat64 struct{}
|
||||
type NilEWMA struct{}
|
||||
type NilGauge struct{}
|
||||
type NilGaugeFloat64 struct{}
|
||||
type NilGaugeInfo struct{}
|
||||
type NilHealthcheck struct{}
|
||||
type NilHistogram struct{}
|
||||
type NilMeter struct{}
|
||||
type NilResettingTimer struct{}
|
||||
type NilSample struct{}
|
||||
type NilTimer struct{}
|
||||
@@ -68,3 +68,6 @@ type StateDatabase interface {
|
||||
// An error will be returned if the specified state is not available.
|
||||
StateReader(stateRoot common.Hash) (StateReader, error)
|
||||
}
|
||||
|
||||
// Reader is an alias for NodeReader for compatibility with coreth
|
||||
type Reader = NodeReader
|
||||
|
||||
Reference in New Issue
Block a user