Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Miner] feat: add Miner component #168

Merged
merged 35 commits into from
Nov 10, 2023
Merged

Conversation

bryanchriswhite
Copy link
Contributor

@bryanchriswhite bryanchriswhite commented Nov 9, 2023

Summary

Human Summary

Ports and refactors the Miner component from poktroll-alpha.

AI Summary

Summary generated by Reviewpad on 10 Nov 23 20:30 UTC

This pull request includes the following changes:

  • The interface.go file in the pkg/relayer package has been modified to add a new import statement and several interface definitions and updates. These changes are related to the implementation of the relayer's session lifecycles and the introduction of a new miner interface.

  • A new file named "miner.go" has been added in the "pkg/relayer/miner" directory. This file defines a package called "miner" and includes the implementation of the relayer.Miner interface. It also contains some utility functions and a constructor for creating a new miner.

  • The relayerSessionsManager struct, defined in a separate file, has been modified to include a new field, relayObs, of type observable.Observable[*relayer.MinedRelay]. The struct also includes methods for managing the relayer's session lifecycles, such as starting and stopping sessions, inserting relays, and ensuring the session tree.

  • Another file named "claim.go" has been added in the pkg/relayer/session package. This file defines the relayerSessionsManager struct and includes methods for creating claims for relayer sessions. These methods use observables to handle asynchronous operations and error handling.

  • A new file named "miner_test.go" has been added in the pkg/relayer/miner package. This file includes a single test function that is currently skipped, indicating that more test coverage needs to be added for the miner implementation.

  • The types.go file in the pkg/relayer package has been modified to introduce a new struct called MinedRelay, which is a wrapper around a serialized and hashed relay. This struct contains two fields, Bytes and Hash, which are of type []byte.

  • The types.go file in the pkg/either package has been modified to add a new import statement and update the SessionTree type, which is now an Either type wrapping relayer.SessionTree. Some type aliases have also been reformatted for clarity.

  • A new file named "difficulty.go" has been added in the pkg/relayer/protocol directory. This file includes the implementation of a function that checks if a given byte slice exceeds a specified difficulty. This function is used to determine if a relay is volume applicable.

These changes are related to the implementation of the relayer's session lifecycles, the introduction of a new miner interface, and the handling of relay claims and proofs. Some areas, such as test coverage and algorithm optimization, have been identified for future improvements.

Please let me know if you need any further assistance!

Issue

Adds the miner component.

Type of change

Select one or more:

  • New feature, functionality or library
  • Bug fix
  • Code health or cleanup
  • Documentation
  • Other (specify)

Testing

  • Run all unit tests: make go_develop_and_test
  • Verify Localnet manually: See the instructions [here](TODO: add link to instructions)

Sanity Checklist

  • I have tested my changes using the available tooling
  • I have performed a self-review of my own code
  • I have commented my code, updated documentation and left TODOs throughout the codebase

@bryanchriswhite bryanchriswhite added miner Changes related to the Miner off-chain Off-chain business logic labels Nov 9, 2023
@bryanchriswhite bryanchriswhite added this to the Shannon TestNet milestone Nov 9, 2023
@bryanchriswhite bryanchriswhite self-assigned this Nov 9, 2023
@bryanchriswhite bryanchriswhite changed the base branch from main to issues/13/refactor/map November 9, 2023 13:56
@bryanchriswhite bryanchriswhite changed the base branch from issues/13/refactor/map to issues/13/feat/observable-utils November 9, 2023 15:35
@bryanchriswhite bryanchriswhite linked an issue Nov 9, 2023 that may be closed by this pull request
10 tasks
Copy link
Contributor

@red-0ne red-0ne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

servicetypes.Relay is a struct, we should work with its pointer

pkg/relayer/interface.go Outdated Show resolved Hide resolved
pkg/relayer/miner/miner.go Outdated Show resolved Hide resolved
pkg/relayer/miner/miner.go Outdated Show resolved Hide resolved
pkg/relayer/miner/miner.go Outdated Show resolved Hide resolved
pkg/relayer/miner/miner.go Outdated Show resolved Hide resolved
pkg/relayer/miner/miner.go Outdated Show resolved Hide resolved
pkg/relayer/miner/miner.go Outdated Show resolved Hide resolved
Copy link
Member

@Olshansk Olshansk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bryanchriswhite NOT a complete review, but just a preliminary one to give early feedback.

pkg/relayer/interface.go Outdated Show resolved Hide resolved
pkg/relayer/protocol/difficulty.go Show resolved Hide resolved
pkg/relayer/miner/miner.go Outdated Show resolved Hide resolved
pkg/relayer/miner/miner.go Outdated Show resolved Hide resolved
pkg/relayer/miner/miner.go Show resolved Hide resolved
pkg/relayer/miner/miner.go Outdated Show resolved Hide resolved
pkg/relayer/miner/miner.go Outdated Show resolved Hide resolved
pkg/relayer/miner/miner.go Outdated Show resolved Hide resolved
pkg/relayer/miner/miner_test.go Show resolved Hide resolved
pkg/relayer/protocol/block_heights.go Outdated Show resolved Hide resolved
Base automatically changed from issues/13/feat/observable-utils to main November 9, 2023 20:14
bryanchriswhite and others added 3 commits November 9, 2023 21:16
* pokt/main:
  [Off-chain] feat: observable utils (#171)
  [Off-chain] refactor: `MapFn`s receive context arg (#170)
- Fixed helpers for localnet regenesis
- Added an application & supplier to the genesis file
- Initializing appMap & supplierMap in E2E tests
- Add support for the app's codec (for unmarshaling responses) in E2E tests
- Adding a placeholder for `e2e/tests/relay.feature`

---

Co-authored-by: harry <[email protected]>
* refactor: `MapFn`s receive context arg

* feat: add `MapExpand` observable operator

* refactor: `RelayerSessionsManager` to be more reactive

* chore: add godoc comment

* chore: review feedback improvements

* trigger CI
pkg/relayer/miner/miner.go Outdated Show resolved Hide resolved
pkg/relayer/miner/miner.go Outdated Show resolved Hide resolved
pkg/relayer/miner/miner.go Outdated Show resolved Hide resolved
pkg/relayer/miner/miner.go Outdated Show resolved Hide resolved
pkg/relayer/miner/miner.go Outdated Show resolved Hide resolved
pkg/relayer/miner/miner.go Outdated Show resolved Hide resolved
earliestCreateClaimHeight :=
protocol.GetEarliestCreateClaimHeight(createClaimWindowStartBlock)

log.Printf("earliest claim submission createClaimWindowStartBlock height for this supplier: %d", earliestCreateClaimHeight)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So are we going to have a bunch of blocking calls to this at any point in time?

Copy link
Contributor Author

@bryanchriswhite bryanchriswhite Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There will be blocking calls made in map functions to delay downstream notifications to happen at precise times.

pkg/relayer/miner/miner.go Outdated Show resolved Hide resolved
pkg/relayer/miner/miner.go Outdated Show resolved Hide resolved
pkg/relayer/miner/miner.go Outdated Show resolved Hide resolved
pkg/relayer/cmd/cmd.go Outdated Show resolved Hide resolved
pkg/relayer/cmd/cmd.go Outdated Show resolved Hide resolved
MinedRelays(
ctx context.Context,
servedRelayObs observable.Observable[*servicetypes.Relay],
) (minedRelaysObs observable.Observable[*MinedRelay])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UNRELATED OPTION NIT: Thoughts on adding a TODO_TECHDEBT: Add the Obs suffix to all Observables in the codebase.

Might be worthing putting it in observable.go if you also agree that it's the right pattern to follow.

EnsureSessionTree(sessionHeader *sessiontypes.SessionHeader) (SessionTree, error)
// IncludeRelays receives an observable of relays that should be included
// in their respective session's SMST (tree).
IncludeRelays(relayObs observable.Observable[*MinedRelay])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on this rename?

Suggested change
IncludeRelays(relayObs observable.Observable[*MinedRelay])
ClaimRelays(minedRelaysObs observable.Observable[*MinedRelay])

Copy link
Contributor Author

@bryanchriswhite bryanchriswhite Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My hesitation with ClaimRelays is that while claming is a consequence of having relays in the SMST by a certain time, that's something that happens as an indirect consequence of IncludeRelays. What this method does directly is insert the observed relays in to the respective session's SMST. Start is where the observable mapping happens such that claims and proofs are created/submitted.

What about InsertRelays?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline. Proof of digital handshake below:
Screenshot 2023-11-10 at 12 02 50 PM

// network as necessary.
Start(ctx context.Context)

// Stop unsubscribes all observables from the RelaysToInclude observable which
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find RelaysToInclude so should this be minedRelaysObs if we rename the parameter above appropriatelY?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, thanks! The method was renamed to IncludeRelays. It's defined on the RelayerSessionManger interface and receives minedRelaysObs. I intentionally avoided referencing mining on that side of the RelayerSessionManager interface because it doesn't need to know anything about mining other than the fact that the MinedRelay provides bytes and hash fields (which could be replaced with and interface in future refactoring).

pkg/relayer/miner/miner.go Outdated Show resolved Hide resolved
pkg/relayer/miner/miner.go Outdated Show resolved Hide resolved
pkg/relayer/session/claim.go Outdated Show resolved Hide resolved
pkg/relayer/session/claim.go Show resolved Hide resolved
pkg/relayer/session/claim.go Outdated Show resolved Hide resolved
pkg/relayer/session/session.go Outdated Show resolved Hide resolved
pkg/relayer/session/session.go Show resolved Hide resolved
@Olshansk
Copy link
Member

@bryanchriswhite All of my comments are only related to naming, comment updates, etc...

Overall, great work and thank you for iterating on top of yesterday's feedback. I feel like this is MUCH MUCH easier to read and understand!

Copy link
Contributor

@red-0ne red-0ne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Splitting responsibilities this way makes it way easier to reason about.

I'll base RelayMiner on this work.

Copy link
Member

@Olshansk Olshansk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

giphy (1)

@bryanchriswhite bryanchriswhite merged commit 5af2ae9 into main Nov 10, 2023
7 checks passed
bryanchriswhite added a commit that referenced this pull request Nov 11, 2023
* pokt/relayer/cli:
  [AppGate] Implement the MVP AppGateServer (#108)
  chore: Improve comment about startig relayer proxy
  [Relayer] feat: Add Relayer struct (#172)
  feat: Use relay miner to start
  chore: Reflect responsibility changes of session manager
  [Miner] feat: add `Miner` component (#168)
  fix: Update Miner interface
  chore: update start mining comment
  chore: Remove unused RelayerOption parameter
  chore: Rename relay miner file
  chore: Rename to RelayMiner
  feat: Add Relayer struct
@bryanchriswhite bryanchriswhite deleted the issues/13/feat/miner branch November 20, 2023 07:05
okdas pushed a commit that referenced this pull request Nov 14, 2024
* refactor: `MapFn`s receive context arg

* chore: add `ForEach` map shorthand operator

* chore: add `/pkg/observable/filter`

* chore: add `/pkg/observable/logging`

* chore: add `/pkg/relayer/protocol`

* chore: add `Miner` interface

* feat: add `Miner` implementation

* test: `Miner` implementation

* chore: fix comment

* chore: add godoc comments

* [Test] First step for automated E2E Relay test (#167)

- Fixed helpers for localnet regenesis
- Added an application & supplier to the genesis file
- Initializing appMap & supplierMap in E2E tests
- Add support for the app's codec (for unmarshaling responses) in E2E tests
- Adding a placeholder for `e2e/tests/relay.feature`

---

Co-authored-by: harry <[email protected]>

* [Relayer] refactor: simplify `RelayerSessionsManager`  (#169)

* refactor: `MapFn`s receive context arg

* feat: add `MapExpand` observable operator

* refactor: `RelayerSessionsManager` to be more reactive

* chore: add godoc comment

* chore: review feedback improvements

* trigger CI

* chore: review feedback improvements

Co-authored-by: Daniel Olshansky <[email protected]>

* chore: review feedback improvements

* fix: import cycle & goimports

* chore: review feedback improvements

* chore: cleanup TODO_THIS_COMMIT comments

* chore: improve var & func names for clarity and consistency

* refactor: move claim/proof lifecycle concerns to `relayerSessionsManager`.

* chore: review feedback improvements

* chore: review feedback improvements

* refactor: `miner#hash()` method

* chore: tidy up

* chore: simplify

* chore: review feedback improvements

Co-authored-by: Daniel Olshansky <[email protected]>

* chore: review feedback improvements

Co-authored-by: Daniel Olshansky <[email protected]>

* chore: review feedback improvements

Co-authored-by: Daniel Olshansky <[email protected]>

* chore: review feedback improvements

* chore: review feedback improvements

* fix: incomplete refactor

* chore: simplify

---------

Co-authored-by: Daniel Olshansky <[email protected]>
Co-authored-by: harry <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
miner Changes related to the Miner off-chain Off-chain business logic
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

[Miner] Foundation for the Miner submodule
3 participants