Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Out of Band Reimbursement Daemon #649

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions containers/threadsafe/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ func (s *Map[K, V]) Delete(k K) {
}
}

func (s *Map[K, V]) Copy() map[K]V {
s.RLock()
defer s.RUnlock()
m := make(map[K]V)
for k, v := range s.items {
m[k] = v
}
return m
}

func (s *Map[K, V]) ForEach(fn func(k K, v V) error) error {
s.RLock()
defer s.RUnlock()
Expand Down
2 changes: 2 additions & 0 deletions testing/endtoend/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ go_test(
"//testing/endtoend/backend",
"//testing/mocks/state-provider",
"//testing/setup:setup_lib",
"//util",
"@com_github_ethereum_go_ethereum//:go-ethereum",
"@com_github_ethereum_go_ethereum//accounts/abi",
"@com_github_ethereum_go_ethereum//accounts/abi/bind",
Expand All @@ -57,6 +58,7 @@ go_library(
"//runtime",
"//solgen/go/rollupgen",
"//testing/setup:setup_lib",
"//util",
"@com_github_ethereum_go_ethereum//accounts/abi/bind",
"@com_github_stretchr_testify//require",
],
Expand Down
2 changes: 2 additions & 0 deletions testing/endtoend/backend/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ go_library(
"//solgen/go/rollupgen",
"//testing",
"//testing/setup:setup_lib",
"//util",
"@com_github_ethereum_go_ethereum//accounts/abi/bind",
"@com_github_ethereum_go_ethereum//common",
"@com_github_ethereum_go_ethereum//common/hexutil",
Expand All @@ -39,6 +40,7 @@ go_test(
visibility = ["//testing/endtoend:__subpackages__"],
deps = [
"//runtime",
"//util",
"@com_github_stretchr_testify//require",
],
)
3 changes: 2 additions & 1 deletion testing/endtoend/backend/anvil_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/OffchainLabs/bold/solgen/go/rollupgen"
challenge_testing "github.com/OffchainLabs/bold/testing"
"github.com/OffchainLabs/bold/testing/setup"
"github.com/OffchainLabs/bold/util"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
Expand Down Expand Up @@ -250,7 +251,7 @@ func (a *AnvilLocal) DeployRollup(ctx context.Context, opts ...challenge_testing
if err != nil {
return nil, err
}
chalManagerAddr, err := rollupCaller.ChallengeManager(&bind.CallOpts{})
chalManagerAddr, err := rollupCaller.ChallengeManager(util.GetSafeCallOpts(&bind.CallOpts{}))
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion testing/endtoend/backend/anvil_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

retry "github.com/OffchainLabs/bold/runtime"
"github.com/OffchainLabs/bold/util"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -45,7 +46,7 @@ func TestLocalAnvilStarts(t *testing.T) {
require.NoError(t, err)

// There should be at least 100 blocks
bn, err2 := a.Client().HeaderByNumber(ctx, nil)
bn, err2 := a.Client().HeaderByNumber(ctx, util.GetSafeBlockNumber())
if err2 != nil {
t.Fatal(err2)
}
Expand Down
3 changes: 3 additions & 0 deletions testing/endtoend/backend/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package backend

import (
"context"
"fmt"
"time"

protocol "github.com/OffchainLabs/bold/chain-abstraction"
Expand Down Expand Up @@ -69,5 +70,7 @@ func NewSimulated(blockTime time.Duration, opts ...setup.Opt) (*LocalSimulatedBa
if err != nil {
return nil, err
}
fmt.Println("Rollup addr", setup.Addrs.Rollup)
time.Sleep(time.Second * 10)
return &LocalSimulatedBackend{blockTime: blockTime, setup: setup}, nil
}
3 changes: 2 additions & 1 deletion testing/endtoend/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ type protocolParams struct {
func defaultProtocolParams() protocolParams {
return protocolParams{
numBigStepLevels: 1,
challengePeriodBlocks: 60,
challengePeriodBlocks: 50,
layerZeroHeights: protocol.LayerZeroHeights{
BlockChallengeHeight: 1 << 5,
BigStepChallengeHeight: 1 << 5,
Expand Down Expand Up @@ -336,6 +336,7 @@ func runEndToEndTest(t *testing.T, cfg *e2eConfig) {
})
}
require.NoError(t, g.Wait())
time.Sleep(time.Hour)
}

type seqMessage struct {
Expand Down
3 changes: 2 additions & 1 deletion testing/endtoend/expectations.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
retry "github.com/OffchainLabs/bold/runtime"
"github.com/OffchainLabs/bold/solgen/go/rollupgen"
"github.com/OffchainLabs/bold/testing/setup"
"github.com/OffchainLabs/bold/util"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -36,7 +37,7 @@ func expectAssertionConfirmedByChallengeWin(
require.NoError(t, err)
for i.Next() {
assertionNode, err := retry.UntilSucceeds(ctx, func() (rollupgen.AssertionNode, error) {
return rc.GetAssertion(&bind.CallOpts{Context: ctx}, i.Event.AssertionHash)
return rc.GetAssertion(util.GetSafeCallOpts(&bind.CallOpts{Context: ctx}), i.Event.AssertionHash)
})
require.NoError(t, err)
if assertionNode.Status != uint8(protocol.AssertionConfirmed) {
Expand Down
3 changes: 2 additions & 1 deletion testing/endtoend/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
challengemanager "github.com/OffchainLabs/bold/challenge-manager"
l2stateprovider "github.com/OffchainLabs/bold/layer2-state-provider"
"github.com/OffchainLabs/bold/solgen/go/rollupgen"
"github.com/OffchainLabs/bold/util"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -35,7 +36,7 @@ func setupChallengeManager(
)
require.NoError(t, err)
challengeManagerAddr, err := assertionChainBinding.RollupUserLogicCaller.ChallengeManager(
&bind.CallOpts{Context: ctx},
util.GetSafeCallOpts(&bind.CallOpts{Context: ctx}),
)
require.NoError(t, err)
chain, err := solimpl.NewAssertionChain(
Expand Down
1 change: 0 additions & 1 deletion testing/mocks/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ go_library(
"//layer2-state-provider",
"//solgen/go/rollupgen",
"//state-commitments/history",
"@com_github_ethereum_go_ethereum//accounts/abi/bind",
"@com_github_ethereum_go_ethereum//common",
"@com_github_ethereum_go_ethereum//core/types",
"@com_github_stretchr_testify//mock",
Expand Down
17 changes: 2 additions & 15 deletions testing/mocks/mocks.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package mocks includes simple mocks for unit testing BOLD.

Check failure on line 1 in testing/mocks/mocks.go

View workflow job for this annotation

GitHub Actions / Lint

: # github.com/OffchainLabs/bold/testing/mocks
//
// Copyright 2023, Offchain Labs, Inc.
// For license information, see https://github.com/offchainlabs/bold/blob/main/LICENSE
Expand All @@ -6,8 +6,6 @@

import (
"context"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"math/big"

protocol "github.com/OffchainLabs/bold/chain-abstraction"
"github.com/OffchainLabs/bold/containers/option"
Expand All @@ -20,9 +18,9 @@
)

var (
_ = protocol.SpecChallengeManager(&MockSpecChallengeManager{})

Check failure on line 21 in testing/mocks/mocks.go

View workflow job for this annotation

GitHub Actions / Lint

cannot convert &MockSpecChallengeManager{} (value of type *MockSpecChallengeManager) to type protocol.SpecChallengeManager: *MockSpecChallengeManager does not implement protocol.SpecChallengeManager (wrong type for method MultiUpdateInheritedTimers)

Check failure on line 21 in testing/mocks/mocks.go

View workflow job for this annotation

GitHub Actions / Lint

cannot convert &MockSpecChallengeManager{} (value of type *MockSpecChallengeManager) to type protocol.SpecChallengeManager: *MockSpecChallengeManager does not implement protocol.SpecChallengeManager (wrong type for method MultiUpdateInheritedTimers)

Check failure on line 21 in testing/mocks/mocks.go

View workflow job for this annotation

GitHub Actions / Lint

cannot convert &MockSpecChallengeManager{} (value of type *MockSpecChallengeManager) to type protocol.SpecChallengeManager: *MockSpecChallengeManager does not implement protocol.SpecChallengeManager (wrong type for method MultiUpdateInheritedTimers)
_ = protocol.SpecEdge(&MockSpecEdge{})
_ = protocol.AssertionChain(&MockProtocol{})

Check failure on line 23 in testing/mocks/mocks.go

View workflow job for this annotation

GitHub Actions / Lint

cannot convert &MockProtocol{} (value of type *MockProtocol) to type protocol.AssertionChain: *MockProtocol does not implement protocol.AssertionChain (missing method GetCallOptsWithDesiredRpcHeadBlockNumber)

Check failure on line 23 in testing/mocks/mocks.go

View workflow job for this annotation

GitHub Actions / Lint

cannot convert &MockProtocol{} (value of type *MockProtocol) to type protocol.AssertionChain: *MockProtocol does not implement protocol.AssertionChain (missing method GetCallOptsWithDesiredRpcHeadBlockNumber)

Check failure on line 23 in testing/mocks/mocks.go

View workflow job for this annotation

GitHub Actions / Lint

cannot convert &MockProtocol{} (value of type *MockProtocol) to type protocol.AssertionChain: *MockProtocol does not implement protocol.AssertionChain (missing method GetCallOptsWithDesiredRpcHeadBlockNumber)
_ = l2stateprovider.Provider(&MockStateManager{})
)

Expand Down Expand Up @@ -168,8 +166,8 @@
args := m.Called(ctx)
return args.Get(0).(uint64), args.Error(1)
}
func (m *MockSpecChallengeManager) MultiUpdateInheritedTimers(ctx context.Context, branch []protocol.ReadOnlyEdge, desiredTimerForLastEdge uint64) (*types.Transaction, error) {
args := m.Called(ctx, branch, desiredTimerForLastEdge)
func (m *MockSpecChallengeManager) MultiUpdateInheritedTimers(ctx context.Context, branch []protocol.ReadOnlyEdge) (*types.Transaction, error) {
args := m.Called(ctx, branch)
return args.Get(0).(*types.Transaction), args.Error(1)
}
func (m *MockSpecChallengeManager) GetEdge(
Expand Down Expand Up @@ -379,17 +377,6 @@
mock.Mock
}

func (m *MockProtocol) GetCallOptsWithDesiredRpcHeadBlockNumber(opts *bind.CallOpts) *bind.CallOpts {
if opts == nil {
opts = &bind.CallOpts{}
}
return opts
}

func (m *MockProtocol) GetDesiredRpcHeadBlockNumber() *big.Int {
return nil
}

// Read-only methods.
func (m *MockProtocol) Backend() protocol.ChainBackend {
args := m.Called()
Expand Down
3 changes: 3 additions & 0 deletions testing/setup/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ go_library(
"//solgen/go/yulgen",
"//testing",
"//testing/mocks/state-provider",
"//util",
"@com_github_ethereum_go_ethereum//:go-ethereum",
"@com_github_ethereum_go_ethereum//accounts/abi",
"@com_github_ethereum_go_ethereum//accounts/abi/bind",
"@com_github_ethereum_go_ethereum//common",
"@com_github_ethereum_go_ethereum//core",
"@com_github_ethereum_go_ethereum//core/types",
"@com_github_ethereum_go_ethereum//crypto",
"@com_github_ethereum_go_ethereum//eth/ethconfig",
"@com_github_ethereum_go_ethereum//ethclient/simulated",
"@com_github_ethereum_go_ethereum//log",
"@com_github_ethereum_go_ethereum//node",
"@com_github_pkg_errors//:errors",
],
)
17 changes: 15 additions & 2 deletions testing/setup/rollup_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ import (
"github.com/OffchainLabs/bold/solgen/go/yulgen"
challenge_testing "github.com/OffchainLabs/bold/testing"
statemanager "github.com/OffchainLabs/bold/testing/mocks/state-provider"
"github.com/OffchainLabs/bold/util"
"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"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/ethclient/simulated"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -320,7 +323,7 @@ func ChainsWithEdgeChallengeManager(opts ...Opt) (*ChainSetup, error) {
}
var challengeManagerAddr common.Address
challengeManagerAddr, err = assertionChainBinding.RollupUserLogicCaller.ChallengeManager(
&bind.CallOpts{Context: ctx},
util.GetSafeCallOpts(&bind.CallOpts{Context: ctx}),
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1032,6 +1035,16 @@ func Accounts(numAccounts uint64) ([]*TestAccount, *SimulatedBackendWrapper, err
TxOpts: txOpts,
}
}
backend := NewSimulatedBackendWrapper(simulated.NewBackend(genesis, simulated.WithBlockGasLimit(gasLimit)))
backend := NewSimulatedBackendWrapper(simulated.NewBackend(genesis, simulated.WithBlockGasLimit(gasLimit), WithHttpApi(8545)))
return accs, backend, nil
}

// WithBlockGasLimit configures the simulated backend to target a specific gas limit
// when producing blocks.
func WithHttpApi(port int) func(nodeConf *node.Config, ethConf *ethconfig.Config) {
return func(nodeConf *node.Config, ethConf *ethconfig.Config) {
nodeConf.HTTPHost = "localhost"
nodeConf.HTTPPort = port
nodeConf.HTTPModules = append(nodeConf.HTTPModules, "eth")
}
}
35 changes: 35 additions & 0 deletions tools/reimbursement-service/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_library(
name = "reimbursement-service_lib",
srcs = [
"challenge_protocol_graph.go",
"event_scraper.go",
"main.go",
"payments.go",
"reimbursement_computation.go",
],
importpath = "github.com/OffchainLabs/bold/tools/reimbursement-service",
visibility = ["//visibility:private"],
deps = [
"//chain-abstraction:protocol",
"//containers/option",
"//containers/threadsafe",
"//solgen/go/challengeV2gen",
"//solgen/go/rollupgen",
"//util",
"@com_github_ethereum_go_ethereum//:go-ethereum",
"@com_github_ethereum_go_ethereum//accounts/abi/bind",
"@com_github_ethereum_go_ethereum//common",
"@com_github_ethereum_go_ethereum//core/types",
"@com_github_ethereum_go_ethereum//ethclient",
"@com_github_ethereum_go_ethereum//log",
"@com_github_ethereum_go_ethereum//rpc",
],
)

go_binary(
name = "reimbursement-service",
embed = [":reimbursement-service_lib"],
visibility = ["//visibility:public"],
)
Loading
Loading