diff --git a/pkg/tbtc/coordination.go b/pkg/tbtc/coordination.go index 99f4b05419..1203ce6187 100644 --- a/pkg/tbtc/coordination.go +++ b/pkg/tbtc/coordination.go @@ -64,7 +64,7 @@ func watchCoordinationWindows( for { select { case block := <-blocksChan: - if block % coordinationFrequencyBlocks == 0 { + if block%coordinationFrequencyBlocks == 0 { // Make sure the current window is not the same as the last one. // There is no guarantee that the block channel will not emit // the same block again. @@ -112,11 +112,11 @@ func newCoordinationExecutor( protocolLatch *generator.ProtocolLatch, ) *coordinationExecutor { return &coordinationExecutor{ - lock: semaphore.NewWeighted(1), - signers: signers, - broadcastChannel: broadcastChannel, + lock: semaphore.NewWeighted(1), + signers: signers, + broadcastChannel: broadcastChannel, membershipValidator: membershipValidator, - protocolLatch: protocolLatch, + protocolLatch: protocolLatch, } } @@ -130,6 +130,7 @@ func (ce *coordinationExecutor) wallet() wallet { // coordinate executes the coordination procedure for the given coordination // window. func (ce *coordinationExecutor) coordinate( + ctx context.Context, window *coordinationWindow, ) (*coordinationResult, error) { if lockAcquired := ce.lock.TryAcquire(1); !lockAcquired { @@ -141,4 +142,4 @@ func (ce *coordinationExecutor) coordinate( // context. return nil, nil -} \ No newline at end of file +} diff --git a/pkg/tbtc/node.go b/pkg/tbtc/node.go index a23bee3d29..43e10db947 100644 --- a/pkg/tbtc/node.go +++ b/pkg/tbtc/node.go @@ -103,14 +103,14 @@ func newNode( scheduler.RegisterProtocol(latch) node := &node{ - groupParameters: groupParameters, - chain: chain, - btcChain: btcChain, - netProvider: netProvider, - walletRegistry: walletRegistry, - walletDispatcher: newWalletDispatcher(), - protocolLatch: latch, - signingExecutors: make(map[string]*signingExecutor), + groupParameters: groupParameters, + chain: chain, + btcChain: btcChain, + netProvider: netProvider, + walletRegistry: walletRegistry, + walletDispatcher: newWalletDispatcher(), + protocolLatch: latch, + signingExecutors: make(map[string]*signingExecutor), coordinationExecutors: make(map[string]*coordinationExecutor), } @@ -648,12 +648,13 @@ type coordinationLayerSettings struct { // executeCoordinationProcedureFn is a function executing the coordination // procedure for the given wallet and coordination window. executeCoordinationProcedureFn func( + ctx context.Context, node *node, window *coordinationWindow, walletPublicKey *ecdsa.PublicKey, ) (*coordinationResult, bool) - // processCoordinationResultFn is a function processing the given + // processCoordinationResultFn is a function processing the given // coordination result. processCoordinationResultFn func( node *node, @@ -702,6 +703,7 @@ func (n *node) runCoordinationLayer( // to the coordination result channel. go func(walletPublicKey *ecdsa.PublicKey) { result, ok := cls.executeCoordinationProcedureFn( + ctx, n, window, walletPublicKey, @@ -738,6 +740,7 @@ func (n *node) runCoordinationLayer( // executeCoordinationProcedure executes the coordination procedure for the // given wallet and coordination window. func executeCoordinationProcedure( + ctx context.Context, node *node, window *coordinationWindow, walletPublicKey *ecdsa.PublicKey, @@ -769,7 +772,7 @@ func executeCoordinationProcedure( return nil, false } - result, err := executor.coordinate(window) + result, err := executor.coordinate(ctx, window) if err != nil { procedureLogger.Errorf("coordination procedure failed: [%v]", err) return nil, false diff --git a/pkg/tbtc/node_test.go b/pkg/tbtc/node_test.go index 2272cd507f..4ce28005d9 100644 --- a/pkg/tbtc/node_test.go +++ b/pkg/tbtc/node_test.go @@ -288,6 +288,7 @@ func TestNode_RunCoordinationLayer(t *testing.T) { // Mock the coordination procedure execution. Return predefined results // on specific coordination windows. executeCoordinationProcedureFn := func( + _ context.Context, _ *node, window *coordinationWindow, walletPublicKey *ecdsa.PublicKey,