Skip to content

Commit

Permalink
chore: review feedback improvements
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Olshansky <[email protected]>
  • Loading branch information
bryanchriswhite and Olshansk authored Nov 10, 2023
1 parent efb8a4e commit 3b2022a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions pkg/relayer/protocol/block_heights.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
20 changes: 11 additions & 9 deletions pkg/relayer/session/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(

Check failure on line 26 in pkg/relayer/session/claim.go

View workflow job for this annotation

GitHub Actions / build

sessionsWithOpenClaimWindowObs declared and not used
ctx, rs.sessionsToClaim,
rs.mapWaitForEarliestCreateClaimHeight,
)

failedCreateClaimSessions, failedCreateClaimSessionsPublishCh :=
failedCreateClaimSessionsObs, failedCreateClaimSessionsPublishCh :=

Check failure on line 31 in pkg/relayer/session/claim.go

View workflow job for this annotation

GitHub Actions / build

failedCreateClaimSessionsObs declared and not used
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,

Check failure on line 38 in pkg/relayer/session/claim.go

View workflow job for this annotation

GitHub Actions / build

undefined: sessionsWithOpenClaimWindow
rs.newMapClaimSessionFn(failedCreateClaimSessionsPublishCh),
)
Expand Down Expand Up @@ -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,
Expand All @@ -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())
Expand Down
17 changes: 9 additions & 8 deletions pkg/relayer/session/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Check failure on line 29 in pkg/relayer/session/proof.go

View workflow job for this annotation

GitHub Actions / build

undefined: claimedSessions
rs.mapWaitForEarliestSubmitProofHeight,
)

failedSubmitProofSessions, failedSubmitProveSessionsPublishCh :=
failedSubmitProofSessionsObs, failedSubmitProveSessionsPublishCh :=

Check failure on line 33 in pkg/relayer/session/proof.go

View workflow job for this annotation

GitHub Actions / build

failedSubmitProofSessionsObs declared and not used
channel.NewObservable[relayer.SessionTree]()

// Map sessionsWithOpenProofWindow to a new observable of an either type,
Expand Down

0 comments on commit 3b2022a

Please sign in to comment.