Skip to content

Commit

Permalink
Merge branch 'master' into p2p-sdk-handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyonur authored Jan 22, 2024
2 parents ae4f5eb + b5f92be commit acd3f4a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
4 changes: 2 additions & 2 deletions accounts/abi/topics.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"reflect"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/crypto"
)

Expand All @@ -50,8 +51,7 @@ func packTopic(rule interface{}) (common.Hash, error) {
case common.Address:
copy(topic[common.HashLength-common.AddressLength:], rule[:])
case *big.Int:
blob := rule.Bytes()
copy(topic[common.HashLength-len(blob):], blob)
copy(topic[:], math.U256Bytes(rule))
case bool:
if rule {
topic[common.HashLength-1] = 1
Expand Down
27 changes: 24 additions & 3 deletions accounts/abi/topics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
package abi

import (
"math"
"math/big"
"reflect"
"testing"
Expand All @@ -35,6 +36,8 @@ import (
"github.com/ethereum/go-ethereum/crypto"
)

var MaxHash = common.HexToHash("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")

func TestMakeTopics(t *testing.T) {
type args struct {
query [][]interface{}
Expand Down Expand Up @@ -64,9 +67,27 @@ func TestMakeTopics(t *testing.T) {
false,
},
{
"support *big.Int types in topics",
args{[][]interface{}{{big.NewInt(1).Lsh(big.NewInt(2), 254)}}},
[][]common.Hash{{common.Hash{128}}},
"support positive *big.Int types in topics",
args{[][]interface{}{
{big.NewInt(1)},
{big.NewInt(1).Lsh(big.NewInt(2), 254)},
}},
[][]common.Hash{
{common.HexToHash("0000000000000000000000000000000000000000000000000000000000000001")},
{common.Hash{128}},
},
false,
},
{
"support negative *big.Int types in topics",
args{[][]interface{}{
{big.NewInt(-1)},
{big.NewInt(math.MinInt64)},
}},
[][]common.Hash{
{MaxHash},
{common.HexToHash("ffffffffffffffffffffffffffffffffffffffffffffffff8000000000000000")},
},
false,
},
{
Expand Down
2 changes: 1 addition & 1 deletion eth/state_accessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (eth *Ethereum) stateAtTransaction(ctx context.Context, block *types.Block,
// apply the upgrades to the [parent] state before returning it.
func (eth *Ethereum) StateAtNextBlock(ctx context.Context, parent *types.Block, nextBlock *types.Block, reexec uint64, base *state.StateDB, readOnly bool, preferDisk bool) (*state.StateDB, tracers.StateReleaseFunc, error) {
// Get state for [parent]
statedb, release, err := eth.StateAtBlock(ctx, parent, reexec, nil, true, false)
statedb, release, err := eth.StateAtBlock(ctx, parent, reexec, base, readOnly, preferDisk)
if err != nil {
return nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion eth/tracers/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (b *testBackend) StateAtBlock(ctx context.Context, block *types.Block, reex
}

func (b *testBackend) StateAtNextBlock(ctx context.Context, parent, nextBlock *types.Block, reexec uint64, base *state.StateDB, readOnly bool, preferDisk bool) (*state.StateDB, StateReleaseFunc, error) {
statedb, release, err := b.StateAtBlock(ctx, parent, reexec, nil, true, false)
statedb, release, err := b.StateAtBlock(ctx, parent, reexec, base, readOnly, preferDisk)
if err != nil {
return nil, nil, err
}
Expand Down
12 changes: 12 additions & 0 deletions ethclient/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/ava-labs/subnet-evm/accounts/abi/bind"
"github.com/ava-labs/subnet-evm/core/types"
"github.com/ava-labs/subnet-evm/interfaces"
"github.com/ava-labs/subnet-evm/params"
"github.com/ava-labs/subnet-evm/rpc"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
Expand Down Expand Up @@ -69,6 +70,7 @@ var (
type Client interface {
Client() *rpc.Client
Close()
ChainConfig(context.Context) (*params.ChainConfigWithUpgradesJSON, error)
ChainID(context.Context) (*big.Int, error)
BlockByHash(context.Context, common.Hash) (*types.Block, error)
BlockByNumber(context.Context, *big.Int) (*types.Block, error)
Expand Down Expand Up @@ -141,6 +143,16 @@ func (ec *client) Client() *rpc.Client {

// Blockchain Access

// ChainConfig retrieves the current chain config.
func (ec *client) ChainConfig(ctx context.Context) (*params.ChainConfigWithUpgradesJSON, error) {
var result *params.ChainConfigWithUpgradesJSON
err := ec.c.CallContext(ctx, &result, "eth_getChainConfig")
if err != nil {
return nil, err
}
return result, err
}

// ChainID retrieves the current chain ID for transaction replay protection.
func (ec *client) ChainID(ctx context.Context) (*big.Int, error) {
var result hexutil.Big
Expand Down

0 comments on commit acd3f4a

Please sign in to comment.