From 3b2022aa01652de1eb73bad7ef2df424eeb23cf5 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Fri, 10 Nov 2023 21:03:19 +0100 Subject: [PATCH] chore: review feedback improvements Co-authored-by: Daniel Olshansky --- pkg/relayer/protocol/block_heights.go | 4 ++-- pkg/relayer/session/claim.go | 20 +++++++++++--------- pkg/relayer/session/proof.go | 17 +++++++++-------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/pkg/relayer/protocol/block_heights.go b/pkg/relayer/protocol/block_heights.go index 330f0fc34..b372376f7 100644 --- a/pkg/relayer/protocol/block_heights.go +++ b/pkg/relayer/protocol/block_heights.go @@ -11,7 +11,7 @@ import ( // GetEarliestCreateClaimHeight returns the earliest block height at which a claim // for a session with the given createClaimWindowStartHeight can be created. // -// TODO_TEST(@bryanchriswhite): Add test coverage +// TODO_TEST(@bryanchriswhite): Add test coverage and more logs func GetEarliestCreateClaimHeight(createClaimWindowStartBlock client.Block) int64 { createClaimWindowStartBlockHash := createClaimWindowStartBlock.Hash() log.Printf("using createClaimWindowStartBlock %d's hash %x as randomness", createClaimWindowStartBlock.Height(), createClaimWindowStartBlockHash) @@ -29,7 +29,7 @@ func GetEarliestCreateClaimHeight(createClaimWindowStartBlock client.Block) int6 // GetEarliestSubmitProofHeight returns the earliest block height at which a proof // for a session with the given submitProofWindowStartHeight can be submitted. // -// TODO_TEST(@bryanchriswhite): Add test coverage. +// TODO_TEST(@bryanchriswhite): Add test coverage and more logs func GetEarliestSubmitProofHeight(submitProofWindowStartBlock client.Block) int64 { earliestSubmitProofBlockHash := submitProofWindowStartBlock.Hash() log.Printf("using submitProofWindowStartBlock %d's hash %x as randomness", submitProofWindowStartBlock.Height(), earliestSubmitProofBlockHash) diff --git a/pkg/relayer/session/claim.go b/pkg/relayer/session/claim.go index 5ecf2fd42..737ad3d9c 100644 --- a/pkg/relayer/session/claim.go +++ b/pkg/relayer/session/claim.go @@ -13,27 +13,28 @@ import ( "github.com/pokt-network/poktroll/pkg/relayer/protocol" ) -// createClaims maps over the sessionsToClaim observable. For each claim, it -// calculates and waits for the earliest block height at which it is safe to -// claim and does so. It then maps any errors to a new observable which are -// subsequently logged. It returns an observable of the successfully claimed -// sessions. It does not block as map operations run in their own goroutines. +// createClaims maps over the sessionsToClaim observable. For each claim, it: +// 1. Calculates the earliest block height at which it is safe to CreateClaim +// 2. Waits for said block and creates the claim on-chain +// 3. Maps errors to a new observable and logs them +// 4. Returns an observable of the successfully claimed sessions +// It DOES NOT BLOCK as map operations run in their own goroutines. func (rs *relayerSessionsManager) createClaims(ctx context.Context) observable.Observable[relayer.SessionTree] { // Map SessionsToClaim observable to a new observable of the same type which // is notified when the session is eligible to be claimed. // relayer.SessionTree ==> relayer.SessionTree - sessionsWithOpenClaimWindow := channel.Map( + sessionsWithOpenClaimWindowObs := channel.Map( ctx, rs.sessionsToClaim, rs.mapWaitForEarliestCreateClaimHeight, ) - failedCreateClaimSessions, failedCreateClaimSessionsPublishCh := + failedCreateClaimSessionsObs, failedCreateClaimSessionsPublishCh := channel.NewObservable[relayer.SessionTree]() // Map sessionsWithOpenClaimWindow to a new observable of an either type, // populated with the session or an error, which is notified after the session // claim has been created or an error has been encountered, respectively. - eitherClaimedSessions := channel.Map( + eitherClaimedSessionsObs := channel.Map( ctx, sessionsWithOpenClaimWindow, rs.newMapClaimSessionFn(failedCreateClaimSessionsPublishCh), ) @@ -65,6 +66,7 @@ func (rs *relayerSessionsManager) mapWaitForEarliestCreateClaimHeight( // earliest block height, allowed by the protocol, at which a claim can be created // for a session with the given sessionEndHeight. It is calculated relative to // sessionEndHeight using on-chain governance parameters and randomized input. +// It IS A BLOCKING function. func (rs *relayerSessionsManager) waitForEarliestCreateClaimHeight( ctx context.Context, sessionEndHeight int64, @@ -77,7 +79,7 @@ func (rs *relayerSessionsManager) waitForEarliestCreateClaimHeight( // we wait for createClaimWindowStartHeight to be received before proceeding since we need its hash // to know where this servicer's claim submission window starts. - log.Printf("waiting for global earliest claim submission createClaimWindowStartBlock height: %d", createClaimWindowStartHeight) + log.Printf("waiting & blocking for global earliest claim submission createClaimWindowStartBlock height: %d", createClaimWindowStartHeight) createClaimWindowStartBlock := rs.waitForBlock(ctx, createClaimWindowStartHeight) log.Printf("received earliest claim submission createClaimWindowStartBlock height: %d, use its hash to have a random submission for the servicer", createClaimWindowStartBlock.Height()) diff --git a/pkg/relayer/session/proof.go b/pkg/relayer/session/proof.go index dbead83be..27bd1ea05 100644 --- a/pkg/relayer/session/proof.go +++ b/pkg/relayer/session/proof.go @@ -13,23 +13,24 @@ import ( "github.com/pokt-network/poktroll/pkg/relayer/protocol" ) -// submitProofs maps over the given claimedSessions observable. For each session, -// it calculates and waits for the earliest block height at which it is safe to -// submit a proof and does so. It then maps any errors to a new observable which -// are subsequently logged. It does not block as map operations run in their own -// goroutines. +// submitProofs maps over the given claimedSessions observable. +// For each session, it: +// 1. Calculates the earliest block height at which to submit a proof +// 2. Waits for said height and submits the proof on-chain +// 3. Maps errors to a new observable and logs them +// It DOES NOT BLOCKas map operations run in their own goroutines. func (rs *relayerSessionsManager) submitProofs( ctx context.Context, - claimedSessions observable.Observable[relayer.SessionTree], + claimedSessionsObs observable.Observable[relayer.SessionTree], ) { // Map claimedSessions to a new observable of the same type which is notified // when the session is eligible to be proven. - sessionsWithOpenProofWindow := channel.Map( + sessionsWithOpenProofWindowObs := channel.Map( ctx, claimedSessions, rs.mapWaitForEarliestSubmitProofHeight, ) - failedSubmitProofSessions, failedSubmitProveSessionsPublishCh := + failedSubmitProofSessionsObs, failedSubmitProveSessionsPublishCh := channel.NewObservable[relayer.SessionTree]() // Map sessionsWithOpenProofWindow to a new observable of an either type,