Commit c04fdd7a authored by Adrian Sutton's avatar Adrian Sutton

op-challenger: Load VM address via new style bindings.

parent 772dbf30
...@@ -28,6 +28,7 @@ const ( ...@@ -28,6 +28,7 @@ const (
methodDefend = "defend" methodDefend = "defend"
methodStep = "step" methodStep = "step"
methodAddLocalData = "addLocalData" methodAddLocalData = "addLocalData"
methodVM = "VM"
) )
type FaultDisputeGameContract struct { type FaultDisputeGameContract struct {
...@@ -145,6 +146,14 @@ func (f *FaultDisputeGameContract) GetAllClaims(ctx context.Context) ([]types.Cl ...@@ -145,6 +146,14 @@ func (f *FaultDisputeGameContract) GetAllClaims(ctx context.Context) ([]types.Cl
return claims, nil return claims, nil
} }
func (f *FaultDisputeGameContract) VMAddr(ctx context.Context) (common.Address, error) {
result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodVM))
if err != nil {
return common.Address{}, fmt.Errorf("failed to fetch VM addr: %w", err)
}
return result.GetAddress(0), nil
}
func (f *FaultDisputeGameContract) AttackTx(parentContractIndex uint64, pivot common.Hash) (txmgr.TxCandidate, error) { func (f *FaultDisputeGameContract) AttackTx(parentContractIndex uint64, pivot common.Hash) (txmgr.TxCandidate, error) {
call := f.contract.Call(methodAttack, new(big.Int).SetUint64(parentContractIndex), pivot) call := f.contract.Call(methodAttack, new(big.Int).SetUint64(parentContractIndex), pivot)
return call.ToTxCandidate() return call.ToTxCandidate()
......
...@@ -74,6 +74,13 @@ func TestSimpleGetters(t *testing.T) { ...@@ -74,6 +74,13 @@ func TestSimpleGetters(t *testing.T) {
return game.CallResolve(context.Background()) return game.CallResolve(context.Background())
}, },
}, },
{
method: methodVM,
result: common.Address{0xab, 0xbc},
call: func(game *FaultDisputeGameContract) (any, error) {
return game.VMAddr(context.Background())
},
},
} }
for _, test := range tests { for _, test := range tests {
test := test test := test
......
...@@ -42,11 +42,12 @@ func RegisterGameTypes( ...@@ -42,11 +42,12 @@ func RegisterGameTypes(
if cfg.TraceTypeEnabled(config.TraceTypeCannon) { if cfg.TraceTypeEnabled(config.TraceTypeCannon) {
resourceCreator := func(addr common.Address, contract *contracts.FaultDisputeGameContract, gameDepth uint64, dir string) (faultTypes.TraceAccessor, faultTypes.OracleUpdater, gameValidator, error) { resourceCreator := func(addr common.Address, contract *contracts.FaultDisputeGameContract, gameDepth uint64, dir string) (faultTypes.TraceAccessor, faultTypes.OracleUpdater, gameValidator, error) {
logger := logger.New("game", addr)
provider, err := cannon.NewTraceProvider(ctx, logger, m, cfg, contract, dir, gameDepth) provider, err := cannon.NewTraceProvider(ctx, logger, m, cfg, contract, dir, gameDepth)
if err != nil { if err != nil {
return nil, nil, nil, fmt.Errorf("create cannon trace provider: %w", err) return nil, nil, nil, fmt.Errorf("create cannon trace provider: %w", err)
} }
updater, err := cannon.NewOracleUpdater(ctx, logger, txMgr, addr, client, contract) updater, err := cannon.NewOracleUpdater(ctx, logger, txMgr, client, contract)
if err != nil { if err != nil {
return nil, nil, nil, fmt.Errorf("failed to create the cannon updater: %w", err) return nil, nil, nil, fmt.Errorf("failed to create the cannon updater: %w", err)
} }
...@@ -66,6 +67,7 @@ func RegisterGameTypes( ...@@ -66,6 +67,7 @@ func RegisterGameTypes(
} }
if cfg.TraceTypeEnabled(config.TraceTypeAlphabet) { if cfg.TraceTypeEnabled(config.TraceTypeAlphabet) {
resourceCreator := func(addr common.Address, contract *contracts.FaultDisputeGameContract, gameDepth uint64, dir string) (faultTypes.TraceAccessor, faultTypes.OracleUpdater, gameValidator, error) { resourceCreator := func(addr common.Address, contract *contracts.FaultDisputeGameContract, gameDepth uint64, dir string) (faultTypes.TraceAccessor, faultTypes.OracleUpdater, gameValidator, error) {
logger := logger.New("game", addr)
provider := alphabet.NewTraceProvider(cfg.AlphabetTrace, gameDepth) provider := alphabet.NewTraceProvider(cfg.AlphabetTrace, gameDepth)
updater := alphabet.NewOracleUpdater(logger) updater := alphabet.NewOracleUpdater(logger)
validator := func(ctx context.Context, contract *contracts.FaultDisputeGameContract) error { validator := func(ctx context.Context, contract *contracts.FaultDisputeGameContract) error {
......
...@@ -17,6 +17,7 @@ import ( ...@@ -17,6 +17,7 @@ import (
) )
type GameContract interface { type GameContract interface {
VMAddr(ctx context.Context) (common.Address, error)
AddLocalDataTx(data *types.PreimageOracleData) (txmgr.TxCandidate, error) AddLocalDataTx(data *types.PreimageOracleData) (txmgr.TxCandidate, error)
} }
...@@ -37,18 +38,13 @@ func NewOracleUpdater( ...@@ -37,18 +38,13 @@ func NewOracleUpdater(
ctx context.Context, ctx context.Context,
logger log.Logger, logger log.Logger,
txMgr txmgr.TxManager, txMgr txmgr.TxManager,
fdgAddr common.Address,
client bind.ContractCaller, client bind.ContractCaller,
gameContract GameContract, gameContract GameContract,
) (*cannonUpdater, error) { ) (*cannonUpdater, error) {
gameCaller, err := bindings.NewFaultDisputeGameCaller(fdgAddr, client)
if err != nil {
return nil, fmt.Errorf("create caller for game %v: %w", fdgAddr, err)
}
opts := &bind.CallOpts{Context: ctx} opts := &bind.CallOpts{Context: ctx}
vm, err := gameCaller.VM(opts) vm, err := gameContract.VMAddr(ctx)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to load VM address from game %v: %w", fdgAddr, err) return nil, fmt.Errorf("failed to load VM address: %w", err)
} }
mipsCaller, err := bindings.NewMIPSCaller(vm, client) mipsCaller, err := bindings.NewMIPSCaller(vm, client)
if err != nil { if err != nil {
...@@ -56,7 +52,7 @@ func NewOracleUpdater( ...@@ -56,7 +52,7 @@ func NewOracleUpdater(
} }
oracleAddr, err := mipsCaller.Oracle(opts) oracleAddr, err := mipsCaller.Oracle(opts)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to load pre-image oracle address from game %v: %w", fdgAddr, err) return nil, fmt.Errorf("failed to load pre-image oracle address: %w", err)
} }
return NewOracleUpdaterWithOracle(logger, txMgr, gameContract, oracleAddr) return NewOracleUpdaterWithOracle(logger, txMgr, gameContract, oracleAddr)
} }
......
...@@ -153,6 +153,10 @@ type mockGameContract struct { ...@@ -153,6 +153,10 @@ type mockGameContract struct {
err error err error
} }
func (m *mockGameContract) AddLocalDataTx(data *types.PreimageOracleData) (txmgr.TxCandidate, error) { func (m *mockGameContract) VMAddr(_ context.Context) (common.Address, error) {
return common.Address{0xcc}, nil
}
func (m *mockGameContract) AddLocalDataTx(_ *types.PreimageOracleData) (txmgr.TxCandidate, error) {
return m.tx, m.err return m.tx, m.err
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment