From d8050dd0a62ecf72f7737225bcb026a1f9cc0b6d Mon Sep 17 00:00:00 2001 From: Eduard S Date: Wed, 9 Dec 2020 16:22:31 +0100 Subject: [PATCH] Update node and coordinator, fix linters --- config/config.go | 11 ++++++----- coordinator/coordinator.go | 2 +- node/node.go | 7 ++++--- prover/prover.go | 38 ++++++++++++++++++-------------------- prover/prover_test.go | 6 ++---- 5 files changed, 31 insertions(+), 33 deletions(-) diff --git a/config/config.go b/config/config.go index 71489a8..e4de25a 100644 --- a/config/config.go +++ b/config/config.go @@ -43,8 +43,9 @@ type Coordinator struct { ConfirmBlocks int64 `validate:"required"` // L1BatchTimeoutPerc is the portion of the range before the L1Batch // timeout that will trigger a schedule to forge an L1Batch - L1BatchTimeoutPerc float64 `validate:"required"` - L2DB struct { + ProofServerPollInterval Duration `validate:"required"` + L1BatchTimeoutPerc float64 `validate:"required"` + L2DB struct { SafetyPeriod common.BatchNum `validate:"required"` MaxTxs uint32 `validate:"required"` TTL Duration `validate:"required"` @@ -69,10 +70,10 @@ type Coordinator struct { DeployGasLimit uint64 `validate:"required"` GasPriceDiv uint64 `validate:"required"` ReceiptTimeout Duration `validate:"required"` - IntervalReceiptLoop Duration `validate:"required"` - // IntervalCheckLoop is the waiting interval between receipt + ReceiptLoopInterval Duration `validate:"required"` + // CheckLoopInterval is the waiting interval between receipt // checks of ethereum transactions in the TxManager - IntervalCheckLoop Duration `validate:"required"` + CheckLoopInterval Duration `validate:"required"` // Attempts is the number of attempts to do an eth client RPC // call before giving up Attempts int `validate:"required"` diff --git a/coordinator/coordinator.go b/coordinator/coordinator.go index 50e6ee5..fa2428d 100644 --- a/coordinator/coordinator.go +++ b/coordinator/coordinator.go @@ -807,7 +807,7 @@ func (p *Pipeline) forgeSendServerProof(ctx context.Context, batchNum common.Bat // 7. Call the selected idle server proof with BatchBuilder output, // save server proof info for batchNum - err = batchInfo.ServerProof.CalculateProof(zkInputs) + err = batchInfo.ServerProof.CalculateProof(ctx, zkInputs) if err != nil { return nil, tracerr.Wrap(err) } diff --git a/node/node.go b/node/node.go index 435bc9b..c34994b 100644 --- a/node/node.go +++ b/node/node.go @@ -96,7 +96,7 @@ func NewNode(mode Mode, cfg *config.Node, coordCfg *config.Coordinator) (*Node, DeployGasLimit: coordCfg.EthClient.DeployGasLimit, GasPriceDiv: coordCfg.EthClient.GasPriceDiv, ReceiptTimeout: coordCfg.EthClient.ReceiptTimeout.Duration, - IntervalReceiptLoop: coordCfg.EthClient.IntervalReceiptLoop.Duration, + IntervalReceiptLoop: coordCfg.EthClient.ReceiptLoopInterval.Duration, } } client, err := eth.NewClient(ethClient, nil, nil, ð.ClientConfig{ @@ -165,7 +165,8 @@ func NewNode(mode Mode, cfg *config.Node, coordCfg *config.Coordinator) (*Node, } serverProofs := make([]prover.Client, len(coordCfg.ServerProofs)) for i, serverProofCfg := range coordCfg.ServerProofs { - serverProofs[i] = prover.NewProofServerClient(serverProofCfg.URL) + serverProofs[i] = prover.NewProofServerClient(serverProofCfg.URL, + coordCfg.ProofServerPollInterval.Duration) } coord, err = coordinator.NewCoordinator( @@ -175,7 +176,7 @@ func NewNode(mode Mode, cfg *config.Node, coordCfg *config.Coordinator) (*Node, L1BatchTimeoutPerc: coordCfg.L1BatchTimeoutPerc, EthClientAttempts: coordCfg.EthClient.Attempts, EthClientAttemptsDelay: coordCfg.EthClient.AttemptsDelay.Duration, - TxManagerCheckInterval: coordCfg.EthClient.IntervalCheckLoop.Duration, + TxManagerCheckInterval: coordCfg.EthClient.CheckLoopInterval.Duration, DebugBatchPath: coordCfg.Debug.BatchPath, Purger: coordinator.PurgerCfg{ PurgeBatchDelay: coordCfg.L2DB.PurgeBatchDelay, diff --git a/prover/prover.go b/prover/prover.go index 124cb4b..4053013 100644 --- a/prover/prover.go +++ b/prover/prover.go @@ -133,7 +133,7 @@ type formFileProvider struct { body []byte } -//nolint:unused +//nolint:unused,deadcode func newFormFileProvider(payload interface{}) (*formFileProvider, error) { body := new(bytes.Buffer) writer := multipart.NewWriter(body) @@ -239,9 +239,8 @@ func (p *ProofServerClient) GetProof(ctx context.Context) (*Proof, error) { return nil, tracerr.Wrap(err) } return &proof, nil - } else { - return nil, errors.New("State is not Success") } + return nil, errors.New("State is not Success") } // Cancel cancels any current proof computation @@ -262,22 +261,21 @@ func (p *ProofServerClient) WaitReady(ctx context.Context) error { if !status.Status.IsInitialized() { err := errors.New("Proof Server is not initialized") return err - } else { - if status.Status.IsReady() { - return nil - } - for { - select { - case <-ctx.Done(): - return tracerr.Wrap(common.ErrDone) - case <-time.After(p.timeCons): - status, err := p.apiStatus(ctx) - if err != nil { - return tracerr.Wrap(err) - } - if status.Status.IsReady() { - return nil - } + } + if status.Status.IsReady() { + return nil + } + for { + select { + case <-ctx.Done(): + return tracerr.Wrap(common.ErrDone) + case <-time.After(p.timeCons): + status, err := p.apiStatus(ctx) + if err != nil { + return tracerr.Wrap(err) + } + if status.Status.IsReady() { + return nil } } } @@ -289,7 +287,7 @@ type MockClient struct { // CalculateProof sends the *common.ZKInputs to the ServerProof to compute the // Proof -func (p *MockClient) CalculateProof(zkInputs *common.ZKInputs) error { +func (p *MockClient) CalculateProof(ctx context.Context, zkInputs *common.ZKInputs) error { return nil } diff --git a/prover/prover_test.go b/prover/prover_test.go index 6bfedc3..b83b766 100644 --- a/prover/prover_test.go +++ b/prover/prover_test.go @@ -47,8 +47,7 @@ func testAPIStatus(t *testing.T) { } func testCalculateProof(t *testing.T) { - var zkInputs *common.ZKInputs - zkInputs = common.NewZKInputs(100, 16, 512, 24, 32, big.NewInt(1)) + zkInputs := common.NewZKInputs(100, 16, 512, 24, 32, big.NewInt(1)) err := proofServerClient.CalculateProof(context.Background(), zkInputs) require.NoError(t, err) } @@ -64,8 +63,7 @@ func testGetProof(t *testing.T) { } func testCancel(t *testing.T) { - var zkInputs *common.ZKInputs - zkInputs = common.NewZKInputs(100, 16, 512, 24, 32, big.NewInt(1)) + zkInputs := common.NewZKInputs(100, 16, 512, 24, 32, big.NewInt(1)) err := proofServerClient.CalculateProof(context.Background(), zkInputs) require.NoError(t, err) // TODO: remove sleep when the server has been reviewed