diff --git a/client/client.go b/client/client.go index a2f80a5..b1255d8 100644 --- a/client/client.go +++ b/client/client.go @@ -104,11 +104,6 @@ const ( BENCH ) -const ( - // How long do we wait for the deposit proof after the deposit phase is over. - depositProofGrace = time.Second * 30 -) - // Trust describes how we perceive the operator. type Trust = string @@ -305,11 +300,11 @@ func (c *Client) CmdDeposit(status chan *CmdStatus, args ...string) { } }() go func() { - depEndBlock := c.params.DepositDoneBlock(epoch) + depEndBlock := c.params.TxDoneBlock(epoch) + c.logOffChain("Waiting for deposit proof until block #%d", depEndBlock) err := c.ethClient.WaitForBlock(ctx, depEndBlock) // Add PowDepth here if needed if err == nil { c.logOffChain("Deposit Phase for Epoch %d ended in block %d", epoch, depEndBlock) - time.Sleep(depositProofGrace) } waitErr <- err }() @@ -350,8 +345,8 @@ func (c *Client) CmdDeposit(status chan *CmdStatus, args ...string) { status <- &CmdStatus{War: "Deposit proof: Operator timed out - resuming protocol"} c.setOpTrust(UNKNOWN) } - // TODO challenge - status <- &CmdStatus{Err: errors.New("TODO challenge")} + + c.challenge(status) } // BalanceProofWatcher waits for the balance proof of an epoch and disputes @@ -410,15 +405,8 @@ func (c *Client) FrozenWatcher() { func (c *Client) handleFrozen(event *bindings.ErdstallFrozen) { epoch := event.Epoch c.setOpTrust(UNTRUSTED) - c.log("❄️ Contract Frozen in epoch #%d", epoch) + c.log("❄️Contract Frozen in epoch #%d", epoch) - c.balMtx.Lock() - defer c.balMtx.Unlock() - bal, ok := c.balances[epoch] - if !ok { - c.logOffChain("No balance-proof available for freeze") - return - } status := make(chan *CmdStatus) defer close(status) go func() { @@ -430,14 +418,30 @@ func (c *Client) handleFrozen(event *bindings.ErdstallFrozen) { } } }() - _, err := c.sendTx("WithdrawFrozen", func(auth *bind.TransactOpts) (*types.Transaction, error) { - return c.contract.WithdrawFrozen(auth, bindings.ErdstallBalance{Epoch: epoch, Account: bal.Account, Value: bal.Value}, bal.Bal.Sig) - }, status) - if err != nil { - status <- &CmdStatus{Err: fmt.Errorf("WithdrawFrozen TX: %w", err)} - return + + c.balMtx.Lock() + bal, ok := c.balances[epoch] + c.balMtx.Unlock() + // Use WithdrawFrozen if we have a balance-proof and RecoverDeposit otherwise. + if ok { + _, err := c.sendTx("WithdrawFrozen", func(auth *bind.TransactOpts) (*types.Transaction, error) { + return c.contract.WithdrawFrozen(auth, bindings.ErdstallBalance{Epoch: epoch, Account: bal.Account, Value: bal.Value}, bal.Bal.Sig) + }, status) + if err != nil { + status <- &CmdStatus{Err: fmt.Errorf("WithdrawFrozen TX: %w", err)} + return + } + c.logOnChain("❄️WithdrawFrozen: Complete") + } else { + _, err := c.sendTx("RecoverDeposit", func(auth *bind.TransactOpts) (*types.Transaction, error) { + return c.contract.RecoverDeposit(auth) + }, status) + if err != nil { + status <- &CmdStatus{Err: fmt.Errorf("❄RecoverDeposit TX: %w", err)} + return + } + c.logOnChain("❄️RecoverDeposit: Complete") } - c.log("❄️ WithdrawFrozen: Complete") } func (c *Client) lastBal() *EpochBalance { @@ -485,13 +489,16 @@ func (c *Client) CmdChallenge(status chan *CmdStatus, args ...string) { lastBlock := atomic.LoadUint64(&c.lastBlock) if c.params.IsChallengeResponsePhase(lastBlock + 1) { status <- &CmdStatus{Msg: "Waiting for next epoch"} - next := c.params.DepositDoneBlock(c.params.ExitEpoch(lastBlock + 1)) + next := c.params.DepositDoneBlock(c.params.DepositEpoch(lastBlock + 1)) if err := c.ethClient.WaitForBlock(c.Ctx(), next); err != nil { status <- &CmdStatus{Err: err} return } } + c.challenge(status) +} +func (c *Client) challenge(status chan *CmdStatus) { tx, err := c.sendTx("Challenge", func(auth *bind.TransactOpts) (*types.Transaction, error) { return c.contract.Challenge(auth) }, status) @@ -521,7 +528,7 @@ func (c *Client) CmdChallenge(status chan *CmdStatus, args ...string) { select { case <-done: // ChallengeReponse phase is over, freeze. - c.log("❄️ Freezing Contract") + c.log("❄️Freezing Contract") _, err := c.sendTx("Freeze", func(auth *bind.TransactOpts) (*types.Transaction, error) { return c.contract.Freeze(auth) }, status) @@ -555,14 +562,8 @@ func (c *Client) sendTx(name string, f func(*bind.TransactOpts) (*types.Transact return nil, err } status <- &CmdStatus{Msg: name + " TX: Mining"} - receipt, err := bind.WaitMined(txCtx(), c.ethClient, tx) - if err != nil { - return nil, err - } - if receipt.Status == types.ReceiptStatusFailed { - return nil, errors.New("Receipt failed") - } - return receipt, nil + + return c.ethClient.ConfirmTransaction(txCtx(), tx, c.ethClient.Account()) } func (c *Client) withdraw(exitEpoch uint64, status chan *CmdStatus) { diff --git a/client/test/client.go b/client/test/client.go index 6403f65..9cf8d86 100644 --- a/client/test/client.go +++ b/client/test/client.go @@ -252,13 +252,10 @@ func (c *Client) call(ctx context.Context, call func(*bind.TransactOpts) (*types return fmt.Errorf("calling contract: %w", err) } - rec, err := bind.WaitMined(ctx, c.ethClient, tx) + rec, err := c.ethClient.ConfirmTransaction(ctx, tx, c.ethClient.Account()) if err != nil { return fmt.Errorf("waiting for block containing TX: %w", err) } - if rec.Status == types.ReceiptStatusFailed { - return fmt.Errorf("execution of contract call failed") - } c.SetMinedBlockNum(uint64(rec.BlockNumber.Int64())) return nil diff --git a/cmd/operator/config.json b/cmd/operator/config.json index 8c5e767..d14717d 100644 --- a/cmd/operator/config.json +++ b/cmd/operator/config.json @@ -7,5 +7,7 @@ "ResponseDuration": 1, "PowDepth": 0, "Port": 8080, - "RespondChallenges": true + "RespondChallenges": true, + "SendDepositProofs": true, + "SendBalanceProofs": true } diff --git a/cmd/operator/main.go b/cmd/operator/main.go index 979ac25..7f427d8 100644 --- a/cmd/operator/main.go +++ b/cmd/operator/main.go @@ -23,7 +23,7 @@ func main() { } log.SetLevel(lvl) - _operator := operator.Setup(cfg) + _operator := operator.Setup(*cfg) err = _operator.Serve(cfg.Port) operator.AssertNoError(err) } diff --git a/eth/client.go b/eth/client.go index 3d01536..9e65131 100644 --- a/eth/client.go +++ b/eth/client.go @@ -106,7 +106,6 @@ func NewClientForWallet( // NewTransactor creates a new transactor. func (cl *Client) NewTransactor(ctx context.Context) (*bind.TransactOpts, error) { tr, err := cl.ContractBackend.NewTransactor(ctx, - big.NewInt(0), DefaultGasLimit, cl.account) if err != nil { diff --git a/go.mod b/go.mod index bdd102b..a46eab0 100644 --- a/go.mod +++ b/go.mod @@ -11,5 +11,5 @@ require ( github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.7.0 github.com/stretchr/testify v1.6.1 - perun.network/go-perun v0.5.2 + perun.network/go-perun v0.5.3-0.20201130161943-52ca47c0a417 ) diff --git a/go.sum b/go.sum index 78c6f5e..9e22ef6 100644 --- a/go.sum +++ b/go.sum @@ -18,7 +18,6 @@ github.com/DataDog/zstd v1.3.6-0.20190409195224-796139022798/go.mod h1:1jcaCB/uf github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/Shopify/sarama v1.23.1/go.mod h1:XLH1GYJnLVE0XCr6KdJGVJRTwY30moWNJ4sERjXX6fs= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= -github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8= github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= github.com/VictoriaMetrics/fastcache v1.5.7 h1:4y6y0G8PRzszQUYIQHHssv/jgPHAb5qQuuDNdCbyAgw= github.com/VictoriaMetrics/fastcache v1.5.7/go.mod h1:ptDBkNMQI4RtmVo8VS/XwRY6RoTu1dAWCbrk+6WsEM8= @@ -26,7 +25,6 @@ github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBA github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= -github.com/allegro/bigcache v1.2.1 h1:hg1sY1raCwic3Vnsvje6TT7/pnZba83LeFck5NrFKSc= github.com/allegro/bigcache v1.2.1/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/aristanetworks/fsnotify v1.4.2/go.mod h1:D/rtu7LpjYM8tRJphJ0hUBYpjai8SfX+aSNsWDTq/Ks= github.com/aristanetworks/glog v0.0.0-20180419172825-c15b03b3054f/go.mod h1:KASm+qXFKs/xjSoWn30NrWBBvdTTQq+UjkhjEJHfSFA= @@ -49,7 +47,6 @@ github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVa github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= -github.com/cespare/cp v0.1.0 h1:SE+dxFebS7Iik5LK0tsi1k9ZCxEaFX4AjQmoyA+1dJk= github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s= github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= @@ -82,20 +79,15 @@ github.com/ethereum/go-ethereum v1.9.23/go.mod h1:JIfVb6esrqALTExdz9hRYvrP0xBDf6 github.com/ethereum/go-ethereum v1.9.24 h1:6AK+ORt3EMDO+FTjzXy/AQwHMbu52J2nYHIjyQX9azQ= github.com/ethereum/go-ethereum v1.9.24/go.mod h1:JIfVb6esrqALTExdz9hRYvrP0xBDf6wCncIu1hNwHpM= github.com/fatih/color v1.3.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc h1:jtW8jbpkO4YirRSyepBOH8E+2HEw6/hKkBvFPwhUN8c= github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/garyburd/redigo v1.6.0/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY= github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff h1:tY80oXqGNY4FhTFhk+o9oFHGINQ/+vhlm8HFzi6znCI= github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww= -github.com/go-kit/kit v0.8.0 h1:Wz+5lgoB0kkuqLEc6NVmwRknTKP6dTGbSqvhZtBI/j0= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= -github.com/go-logfmt/logfmt v0.4.0 h1:MP4Eh7ZCb31lleYCFuwm0oe4/YGak+5l1vA2NOE80nA= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= -github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E= github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8= github.com/go-sourcemap/sourcemap v2.1.2+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg= github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= @@ -119,7 +111,6 @@ github.com/golang/snappy v0.0.2-0.20200707131729-196ae77b8a26/go.mod h1:/XxbfmMg github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -160,19 +151,14 @@ github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6 github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/klauspost/reedsolomon v1.9.2/go.mod h1:CwCi+NUr9pqSVktrkN+Ondf06rkhYZ/pcNv7fu+8Un4= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 h1:T+h1c/A9Gawja4Y9mFVWj2vyii2bbUNDw3kt9VxK2EY= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= -github.com/mattn/go-colorable v0.1.0 h1:v2XXALHHh6zHfYTJ+cSkwtyffnaOyR1MXaA91mTrb8o= github.com/mattn/go-colorable v0.1.0/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-ieproxy v0.0.0-20190610004146-91bb50d98149/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc= github.com/mattn/go-ieproxy v0.0.0-20190702010315-6dee0af9227d/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc= -github.com/mattn/go-isatty v0.0.5-0.20180830101745-3fb116b82035 h1:USWjF42jDCSEeikX/G1g40ZWnsPXN5WkZ4jMHZWyBK4= github.com/mattn/go-isatty v0.0.5-0.20180830101745-3fb116b82035/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y= @@ -191,7 +177,6 @@ github.com/naoina/go-stringutil v0.1.0/go.mod h1:XJ2SJL9jCtBh+P9q5btrd/Ylo8XwT/h github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416/go.mod h1:NBIhNtsFMo3G2szEBne+bO4gS192HuIYRqfvOWb4i1E= github.com/nsf/termbox-go v0.0.0-20201107200903-9b52a5faed9e h1:T8/SzSWIDoWV9trslLNfUdJ5yHrIXXuODEy5M0vou4U= github.com/nsf/termbox-go v0.0.0-20201107200903-9b52a5faed9e/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ= -github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= @@ -201,12 +186,10 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.14.0 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA= github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= -github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/openconfig/gnmi v0.0.0-20190823184014-89b2bf29312c/go.mod h1:t+O9It+LKzfOAhKTT5O0ehDix+MTqbtT0T9t+7zzOvc= github.com/openconfig/reference v0.0.0-20190727015836-8dfd928c9696/go.mod h1:ym2A+zigScwkSEb/cVQB0/ZMpU3rqiH6X7WRRsxgOGw= @@ -242,7 +225,6 @@ github.com/rjeczalik/notify v0.9.1/go.mod h1:rKwnCoCGeuQnwBtTSPL9Dad03Vh2n40ePRr github.com/rjeczalik/notify v0.9.2 h1:MiTWrPj55mNDHEiIX5YUSKefw/+lCQVoAFmD6oQm5w8= github.com/rjeczalik/notify v0.9.2/go.mod h1:aErll2f0sUX9PXZnVNyeiObbmTlk5jnMoCa4QEjJeqM= github.com/rs/cors v0.0.0-20160617231935-a62a804a8a00/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= -github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/xhandler v0.0.0-20160618193221-ed27b6fd6521/go.mod h1:RvLn4FgxWubrpZHtQLnOf6EwhN2hEMusxZOhcW9H3UQ= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= @@ -346,7 +328,6 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= @@ -358,7 +339,6 @@ golang.org/x/tools v0.0.0-20200117012304-6edc0a871e69/go.mod h1:TB2adYChydJhpapK golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= @@ -373,7 +353,6 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/bsm/ratelimit.v1 v1.0.0-20160220154919-db14e161995a/go.mod h1:KF9sEfUPAXdG8Oev9e99iLGnl2uJMjc5B+4y3O7x610= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fatih/set.v0 v0.2.1/go.mod h1:5eLWEndGL4zGGemXWrKuts+wTJR0y+w+auqUJZbmyBg= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= @@ -383,23 +362,18 @@ gopkg.in/jcmturner/goidentity.v3 v3.0.0/go.mod h1:oG2kH0IvSYNIu80dVAyu/yoefjq1mN gopkg.in/jcmturner/gokrb5.v7 v7.2.3/go.mod h1:l8VISx+WGYp+Fp7KRbsiUuXTTOnxIc3Tuvyavf11/WM= gopkg.in/jcmturner/rpc.v1 v1.1.0/go.mod h1:YIdkC4XfD6GXbzje11McwsDuOlZQSb9W4vfLvuNnlv8= gopkg.in/karalabe/cookiejar.v2 v2.0.0-20150724131613-8dcd6a7f4951/go.mod h1:owOxCRGGeAx1uugABik6K9oeNu1cgxP/R9ItzLDxNWA= -gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7GC73Ei8pv4MzjDUNPHgQWJdtMAaDU= gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce/go.mod h1:5AcXVHNjg+BDxry382+8OKon8SEWiKktQR07RKPsv1c= -gopkg.in/olebedev/go-duktape.v3 v3.0.0-20200619000410-60c24ae608a6 h1:a6cXbcDDUkSBlpnkWV1bJ+vv3mOgQEltEJ2rPxroVu0= gopkg.in/olebedev/go-duktape.v3 v3.0.0-20200619000410-60c24ae608a6/go.mod h1:uAJfkITjFhyEEuUfm7bsmCZRbW5WRq8s9EY8HZ6hCns= gopkg.in/redis.v4 v4.2.4/go.mod h1:8KREHdypkCEojGKQcjMqAODMICIVwZAONWq8RowTITA= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/urfave/cli.v1 v1.20.0 h1:NdAVW6RYxDif9DhDHaAortIu956m2c0v+09AZBPTbE0= gopkg.in/urfave/cli.v1 v1.20.0/go.mod h1:vuBzUtMdQeixQj8LVd+/98pzhxNGQoyuPBlsXHOQNO0= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -perun.network/go-perun v0.5.2 h1:uLanEFJBpkmG6mxSynAid4DV8iaNlwgnSdLRAquBCz0= -perun.network/go-perun v0.5.2/go.mod h1:oP+MSlHeWKRwdiCafvxlvWr2qvpFDp8z4E097ePGxW8= +perun.network/go-perun v0.5.3-0.20201130161943-52ca47c0a417 h1:YkkFtWhKN+XCVguUCgGZbjW3qYBD4CXHwy0zFqvwjwE= +perun.network/go-perun v0.5.3-0.20201130161943-52ca47c0a417/go.mod h1:oP+MSlHeWKRwdiCafvxlvWr2qvpFDp8z4E097ePGxW8= diff --git a/operator/config.go b/operator/config.go index 8a93758..a260ea0 100644 --- a/operator/config.go +++ b/operator/config.go @@ -20,6 +20,8 @@ type Config struct { PowDepth uint64 Port int RespondChallenges bool + SendDepositProofs bool + SendBalanceProofs bool } // dialTimeout will be used a timeout when dialing to the ethereum node. diff --git a/operator/operator.go b/operator/operator.go index ca1c8f7..1f1831c 100644 --- a/operator/operator.go +++ b/operator/operator.go @@ -10,8 +10,6 @@ import ( "net/rpc" "time" - "github.com/ethereum/go-ethereum/accounts/abi/bind" - "github.com/ethereum/go-ethereum/core/types" hdwallet "github.com/miguelmota/go-ethereum-hdwallet" log "github.com/sirupsen/logrus" perrors "perun.network/go-perun/pkg/errors" @@ -29,8 +27,8 @@ type Operator struct { ethClient *eth.Client *depositProofs *balanceProofs - contract *bindings.Erdstall - respondChallenges bool + contract *bindings.Erdstall + cfg Config } // EnclaveParams returns the enclave parameters. @@ -43,30 +41,30 @@ func New( enclave tee.Enclave, params tee.Parameters, client *eth.Client, - respondChallenges bool, + cfg Config, ) (*Operator, error) { _contract, err := bindings.NewErdstall(params.Contract, client) if err != nil { return nil, fmt.Errorf("loading contract: %w", err) } - if !respondChallenges { - log.Warn("Operator will not respond to on-chain challenges.") + if !cfg.RespondChallenges || !cfg.SendDepositProofs || !cfg.SendBalanceProofs { + log.Warnf("Operator will respond to challenges: %t, send out deposit proofs: %t, send out balance proofs: %t", cfg.RespondChallenges, cfg.SendDepositProofs, cfg.SendBalanceProofs) } return &Operator{ - enclave: enclave, - params: params, - ethClient: client, - depositProofs: newDepositProofs(), - balanceProofs: newBalanceProofs(), - contract: _contract, - respondChallenges: respondChallenges, + enclave: enclave, + params: params, + ethClient: client, + depositProofs: newDepositProofs(), + balanceProofs: newBalanceProofs(), + contract: _contract, + cfg: cfg, }, nil } // Setup creates an operator from the given configuration. -func Setup(cfg *Config) *Operator { +func Setup(cfg Config) *Operator { wallet, err := hdwallet.NewFromMnemonic(cfg.Mnemonic) AssertNoError(err) @@ -101,7 +99,7 @@ func Setup(cfg *Config) *Operator { AssertNoError(err) log.Infof("Operator.Setup: Contract deployed at %s", params.Contract.String()) - operator, err := New(enclave, params, client, cfg.RespondChallenges) + operator, err := New(enclave, params, client, cfg) AssertNoError(err) return operator @@ -194,7 +192,7 @@ func (operator *Operator) handleChallenges() error { } func (operator *Operator) handleChallengedEvent(c challengedEvent) error { - if !operator.respondChallenges { + if !operator.cfg.RespondChallenges { log.Warn("Operator.handleChallengedEvent: ignoring challenges, returning.") return nil } @@ -228,17 +226,11 @@ func (operator *Operator) handleChallengedEvent(c challengedEvent) error { ctx, cancel := createOnChainContext() defer cancel() - r, err := bind.WaitMined(ctx, operator.ethClient.ContractBackend, tx) - if err != nil { + if _, err := operator.ethClient.ConfirmTransaction(ctx, tx, operator.ethClient.Account()); err != nil { log.Errorf("Operator.handleChallengedEvent: Failed to wait for mining of response to challenge %v: %v", c, err) return } - if r.Status != types.ReceiptStatusSuccessful { - log.Errorf("Operator.handleChallengedEvent: Failed to complete response transaction for challenge %v", c) - return - } - log.Infof("Operator.handleChallengedEvent: Resolved dispute for challenge %v", c) }() @@ -246,6 +238,11 @@ func (operator *Operator) handleChallengedEvent(c challengedEvent) error { } func (operator *Operator) handleDepositProofs() error { + if !operator.cfg.SendDepositProofs { + log.Warn("Ignoring deposit proofs") + return nil + } + for { dps, err := operator.enclave.DepositProofs() if err != nil { @@ -259,6 +256,11 @@ func (operator *Operator) handleDepositProofs() error { } func (operator *Operator) handleBalanceProofs() error { + if !operator.cfg.SendDepositProofs { + log.Warn("Ignoring balance proofs") + return nil + } + for { bps, err := operator.enclave.BalanceProofs() if err != nil { diff --git a/operator/operator_test.go b/operator/operator_test.go index 657b838..7d23cd2 100644 --- a/operator/operator_test.go +++ b/operator/operator_test.go @@ -136,7 +136,7 @@ func initEnvironment(t *testing.T) *environment { log.Fatal(err) } - operator := Setup(cfg) + operator := Setup(*cfg) params := operator.EnclaveParams() log.Info("operator_test.initEnvironment: Created operator") errg.Go(func() error { @@ -228,5 +228,7 @@ func newDefaultConfig() *Config { 0, 8080, true, + true, + true, } } diff --git a/operator/test/user.go b/operator/test/user.go index 9da3f90..aea32b4 100644 --- a/operator/test/user.go +++ b/operator/test/user.go @@ -8,9 +8,7 @@ import ( "time" "github.com/ethereum/go-ethereum/accounts" - "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/event" log "github.com/sirupsen/logrus" @@ -99,14 +97,10 @@ func (u *User) Deposit() { u.Fatal("depositing:", err) } - r, err := bind.WaitMined(ctx, u.ethClient, tx) + r, err := u.ethClient.ConfirmTransaction(ctx, tx, u.ethClient.Account()) if err != nil { u.Fatal("waiting for transaction confirmation:", err) } - - if r.Status != types.ReceiptStatusSuccessful { - u.Fatal("deposit transaction failed:", err) - } log.Debugf("Deposited %d in block %d", u.TargetBalance, r.BlockNumber.Uint64()) } @@ -196,12 +190,7 @@ func (u *User) Challenge() { u.Fatal("sending challenge transaction:", err) } - r, err := bind.WaitMined(ctx, u.ethClient, tx) - if err != nil { + if _, err = u.ethClient.ConfirmTransaction(ctx, tx, u.ethClient.Account()); err != nil { u.Fatal("waiting for transaction confirmation:", err) } - - if r.Status != types.ReceiptStatusSuccessful { - u.Fatal("challenge transaction failed:", err) - } } diff --git a/tee/params.go b/tee/params.go index ec599fb..2475abc 100644 --- a/tee/params.go +++ b/tee/params.go @@ -54,3 +54,11 @@ func (p Parameters) DepositStartBlock(epoch uint64) uint64 { func (p Parameters) DepositDoneBlock(epoch uint64) uint64 { return p.DepositStartBlock(epoch) + p.PhaseDuration } + +func (p Parameters) TxDoneBlock(epoch uint64) uint64 { + return p.DepositStartBlock(epoch) + 2*p.PhaseDuration +} + +func (p Parameters) ExitDoneBlock(epoch uint64) uint64 { + return p.DepositStartBlock(epoch) + 3*p.PhaseDuration +}