Skip to content

Commit

Permalink
chore(op-challenger): address comments(remove unused filter)
Browse files Browse the repository at this point in the history
  • Loading branch information
dajuguan committed Oct 26, 2024
1 parent 8db70b8 commit 94a6133
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 70 deletions.
2 changes: 1 addition & 1 deletion op-challenger/game/fault/contracts/delayed_weth.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewDelayedWETHContract(metrics metrics.ContractMetricer, addr common.Addres
return &DelayedWETHContract{
metrics: metrics,
multiCaller: caller,
contract: batching.NewBoundContract(contractAbi, addr, caller),
contract: batching.NewBoundContract(contractAbi, addr),
}
}

Expand Down
60 changes: 4 additions & 56 deletions op-challenger/game/fault/contracts/faultdisputegame.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts/metrics"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
gameTypes "github.com/ethereum-optimism/optimism/op-challenger/game/types"
"github.com/ethereum-optimism/optimism/op-e2e/bindings"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
Expand Down Expand Up @@ -98,7 +97,7 @@ func NewFaultDisputeGameContract(ctx context.Context, metrics metrics.ContractMe
FaultDisputeGameContractLatest: FaultDisputeGameContractLatest{
metrics: metrics,
multiCaller: caller,
contract: batching.NewBoundContract(legacyAbi, addr, caller),
contract: batching.NewBoundContract(legacyAbi, addr),
},
}, nil
} else if strings.HasPrefix(version, "0.18.") || strings.HasPrefix(version, "1.0.") {
Expand All @@ -108,7 +107,7 @@ func NewFaultDisputeGameContract(ctx context.Context, metrics metrics.ContractMe
FaultDisputeGameContractLatest: FaultDisputeGameContractLatest{
metrics: metrics,
multiCaller: caller,
contract: batching.NewBoundContract(legacyAbi, addr, caller),
contract: batching.NewBoundContract(legacyAbi, addr),
},
}, nil
} else if strings.HasPrefix(version, "1.1.") {
Expand All @@ -118,14 +117,14 @@ func NewFaultDisputeGameContract(ctx context.Context, metrics metrics.ContractMe
FaultDisputeGameContractLatest: FaultDisputeGameContractLatest{
metrics: metrics,
multiCaller: caller,
contract: batching.NewBoundContract(legacyAbi, addr, caller),
contract: batching.NewBoundContract(legacyAbi, addr),
},
}, nil
} else {
return &FaultDisputeGameContractLatest{
metrics: metrics,
multiCaller: caller,
contract: batching.NewBoundContract(contractAbi, addr, caller),
contract: batching.NewBoundContract(contractAbi, addr),
}, nil
}
}
Expand Down Expand Up @@ -444,57 +443,6 @@ func (f *FaultDisputeGameContractLatest) GetAllClaims(ctx context.Context, block
return claims, nil
}

func (f *FaultDisputeGameContractLatest) GetSubClaims(ctx context.Context, block rpcblock.Block, aggClaim *types.Claim) ([]common.Hash, error) {
defer f.metrics.StartContractRequest("GetAllSubClaims")()

filter, err := bindings.NewFaultDisputeGameFilterer(f.contract.Addr(), f.multiCaller)
if err != nil {
return nil, err
}

parentIndex := [...]*big.Int{big.NewInt(int64(aggClaim.ParentContractIndex))}
claim := [...][32]byte{aggClaim.ClaimData.ValueBytes()}
claimant := [...]common.Address{aggClaim.Claimant}
moveIter, err := filter.FilterMove(nil, parentIndex[:], claim[:], claimant[:])
if err != nil {
return nil, fmt.Errorf("failed to filter move event log: %w", err)
}
ok := moveIter.Next()
if !ok {
return nil, fmt.Errorf("failed to get move event log: %w", moveIter.Error())
}
txHash := moveIter.Event.Raw.TxHash

// todo: replace hardcoded method name
txCall := batching.NewTxGetByHash(f.contract.Abi(), txHash, "move")
result, err := f.multiCaller.SingleCall(ctx, rpcblock.Latest, txCall)
if err != nil {
return nil, fmt.Errorf("failed to load claim calldata: %w", err)
}

txn, err := txCall.DecodeToTx(result)
if err != nil {
return nil, fmt.Errorf("failed to decode tx: %w", err)
}

var subClaims []common.Hash

if len(txn.BlobHashes()) > 0 {
// todo: fetch Blobs and unpack it into subClaims
return nil, fmt.Errorf("blob tx hasn't been supported")
} else {
inputMap, err := txCall.UnpackCallData(txn)
if err != nil {
return nil, fmt.Errorf("failed to unpack tx resp: %w", err)
}
// todo: replace claim with nary-subclaims
claim := *abi.ConvertType(inputMap[subClaimField], new([32]byte)).(*[32]byte)
subClaims = append(subClaims, claim)
}

return subClaims, nil
}

func (f *FaultDisputeGameContractLatest) IsResolved(ctx context.Context, block rpcblock.Block, claims ...types.Claim) ([]bool, error) {
defer f.metrics.StartContractRequest("IsResolved")()
calls := make([]batching.Call, 0, len(claims))
Expand Down
65 changes: 65 additions & 0 deletions op-challenger/game/fault/contracts/faultdisputegame2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package contracts

import (
"context"
"fmt"
"math/big"

"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
"github.com/ethereum-optimism/optimism/op-e2e/bindings"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
)

func (f *FaultDisputeGameContractLatest) GetSubClaims(ctx context.Context, block rpcblock.Block, aggClaim *types.Claim) ([]common.Hash, error) {
defer f.metrics.StartContractRequest("GetAllSubClaims")()

filter, err := bindings.NewFaultDisputeGameFilterer(f.contract.Addr(), f.multiCaller)
if err != nil {
return nil, err
}

parentIndex := [...]*big.Int{big.NewInt(int64(aggClaim.ParentContractIndex))}
claim := [...][32]byte{aggClaim.ClaimData.ValueBytes()}
claimant := [...]common.Address{aggClaim.Claimant}
moveIter, err := filter.FilterMove(nil, parentIndex[:], claim[:], claimant[:])
if err != nil {
return nil, fmt.Errorf("failed to filter move event log: %w", err)
}
ok := moveIter.Next()
if !ok {
return nil, fmt.Errorf("failed to get move event log: %w", moveIter.Error())
}
txHash := moveIter.Event.Raw.TxHash

// todo: replace hardcoded method name
txCall := batching.NewTxGetByHash(f.contract.Abi(), txHash, "move")
result, err := f.multiCaller.SingleCall(ctx, rpcblock.Latest, txCall)
if err != nil {
return nil, fmt.Errorf("failed to load claim calldata: %w", err)
}

txn, err := txCall.DecodeToTx(result)
if err != nil {
return nil, fmt.Errorf("failed to decode tx: %w", err)
}

var subClaims []common.Hash

if len(txn.BlobHashes()) > 0 {
// todo: fetch Blobs and unpack it into subClaims
return nil, fmt.Errorf("blob tx hasn't been supported")
} else {
inputMap, err := txCall.UnpackCallData(txn)
if err != nil {
return nil, fmt.Errorf("failed to unpack tx resp: %w", err)
}
// todo: replace claim with nary-subclaims
claim := *abi.ConvertType(inputMap[subClaimField], new([32]byte)).(*[32]byte)
subClaims = append(subClaims, claim)
}

return subClaims, nil
}
2 changes: 1 addition & 1 deletion op-challenger/game/fault/contracts/gamefactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewDisputeGameFactoryContract(m metrics.ContractMetricer, addr common.Addre
return &DisputeGameFactoryContract{
metrics: m,
multiCaller: caller,
contract: batching.NewBoundContract(factoryAbi, addr, caller),
contract: batching.NewBoundContract(factoryAbi, addr),
abi: factoryAbi,
}
}
Expand Down
2 changes: 1 addition & 1 deletion op-challenger/game/fault/contracts/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func NewPreimageOracleContract(addr common.Address, caller *batching.MultiCaller
return &PreimageOracleContract{
addr: addr,
multiCaller: caller,
contract: batching.NewBoundContract(oracleAbi, addr, caller),
contract: batching.NewBoundContract(oracleAbi, addr),
}
}

Expand Down
2 changes: 1 addition & 1 deletion op-challenger/game/fault/contracts/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewVMContract(addr common.Address, caller *batching.MultiCaller) *VMContrac

return &VMContract{
multiCaller: caller,
contract: batching.NewBoundContract(mipsAbi, addr, caller),
contract: batching.NewBoundContract(mipsAbi, addr),
}
}

Expand Down
13 changes: 5 additions & 8 deletions op-service/sources/batching/bound.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)
Expand All @@ -18,16 +17,14 @@ var (
)

type BoundContract struct {
abi *abi.ABI
addr common.Address
filter bind.ContractFilterer
abi *abi.ABI
addr common.Address
}

func NewBoundContract(abi *abi.ABI, addr common.Address, filter bind.ContractFilterer) *BoundContract {
func NewBoundContract(abi *abi.ABI, addr common.Address) *BoundContract {
return &BoundContract{
abi: abi,
addr: addr,
filter: filter,
abi: abi,
addr: addr,
}
}

Expand Down
4 changes: 2 additions & 2 deletions op-service/sources/batching/bound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestDecodeCall(t *testing.T) {
validData, err := testAbi.Pack(method, spender, amount)
require.NoError(t, err)

contract := NewBoundContract(testAbi, common.Address{0xaa}, nil)
contract := NewBoundContract(testAbi, common.Address{0xaa})
t.Run("TooShort", func(t *testing.T) {
_, _, err := contract.DecodeCall([]byte{1, 2, 3})
require.ErrorIs(t, err, ErrUnknownMethod)
Expand Down Expand Up @@ -60,7 +60,7 @@ func TestDecodeEvent(t *testing.T) {
// event Transfer(address indexed from, address indexed to, uint256 amount);
event := testAbi.Events["Transfer"]

contract := NewBoundContract(testAbi, common.Address{0xaa}, nil)
contract := NewBoundContract(testAbi, common.Address{0xaa})
t.Run("NoTopics", func(t *testing.T) {
log := &types.Log{}
_, _, err := contract.DecodeEvent(log)
Expand Down

0 comments on commit 94a6133

Please sign in to comment.