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

[Morse->Shannon Migration] feat: implement Morse account state upload #1047

Open
wants to merge 4 commits into
base: issues/1034/scaffold/morse_account_state
Choose a base branch
from

Conversation

bryanchriswhite
Copy link
Contributor

@bryanchriswhite bryanchriswhite commented Jan 29, 2025

Summary

Implement Morse account state upload to Shannon.

Changes:

  • Promote Morse export state & Morse account state to a testutil pkg.
  • Test & implement MsgCreateMorseAccountState handler.

Issue

Type of change

Select one or more from the following:

Sanity Checklist

  • I have updated the GitHub Issue assignees, reviewers, labels, project, iteration and milestone
  • For docs, I have run make docusaurus_start
  • For code, I have run make go_develop_and_test and make test_e2e
  • For code, I have added the devnet-test-e2e label to run E2E tests in CI
  • For configurations, I have update the documentation
  • I added TODOs where applicable

@bryanchriswhite bryanchriswhite added on-chain On-chain business logic consensus-breaking IMPORTANT! If the PR with this tag is merged, next release WILL HAVE TO BE an upgrade. labels Jan 29, 2025
@bryanchriswhite bryanchriswhite self-assigned this Jan 29, 2025
@bryanchriswhite bryanchriswhite force-pushed the issues/1034/feat/upload-state branch 2 times, most recently from 7b536e8 to b90f019 Compare January 29, 2025 14:32
@bryanchriswhite bryanchriswhite marked this pull request as ready for review January 29, 2025 15:30
@bryanchriswhite bryanchriswhite force-pushed the issues/1034/feat/upload-state branch from 74601cc to 1add213 Compare January 29, 2025 15:57
@Olshansk Olshansk added the migration Morse to Shannon migration related work label Jan 29, 2025
@Olshansk Olshansk self-requested a review January 29, 2025 18:29
"github.com/cosmos/gogoproto/proto"
)

func (m MorseAccountState) GetHash() ([]byte, error) {
Copy link
Member

Choose a reason for hiding this comment

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

#PUC

  1. That it uses sha256
  2. It is not a "blockchain state hash" but a hash of the structure. Important destinction

import "poktroll/shared/service.proto";
import "poktroll/migration/types.proto";

// EventUploadMorseState is emitted when a new state hash is uploaded.
Copy link
Member

Choose a reason for hiding this comment

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

  1. EventUploadMorseState != EventCreateMorseAccountState
  2. state hash or the whole thing?


// EventUploadMorseState is emitted when a new state hash is uploaded.
message EventCreateMorseAccountState {
int64 height = 1 [(gogoproto.jsontag) = "height"];
Copy link
Member

Choose a reason for hiding this comment

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

Is this a snapshot height or the height of morse?

func (k msgServer) CreateMorseAccountState(goCtx context.Context, msg *types.MsgCreateMorseAccountState) (*types.MsgCreateMorseAccountStateResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
func (k msgServer) CreateMorseAccountState(ctx context.Context, msg *types.MsgCreateMorseAccountState) (*types.MsgCreateMorseAccountStateResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
Copy link
Member

Choose a reason for hiding this comment

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

Please add some logging

return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "already set")
return nil, status.Error(
codes.FailedPrecondition,
sdkerrors.ErrInvalidRequest.Wrap("already set").Error(),
Copy link
Member

Choose a reason for hiding this comment

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

Not a TODO, but just an FYI that we may need to handle updates.

No one knows what the requirements of that will look like yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we SHOULD NOT. This is a very slippery slope. My expectation is that we do one or more "dress rehearsals" on Shannon testnet, using real Morse migration state, prior to doing it on Shannon mainnet.

Supporting updates to the imported account state necessarily adds very noteworthy complexity that I don't think really gives us any value in return.

See: #1045 (comment)

msg.MorseAccountState,
)
return &types.MsgCreateMorseAccountStateResponse{}, nil

stateHash, err := msg.MorseAccountState.GetHash()
Copy link
Member

Choose a reason for hiding this comment

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

Confirming that this is the actual "Morse Blockchain State Hash" and not just a "hash of the snapshot we make"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will #PUC, it is a hash of the unsigned MsgCreateMorseAccountState.


if err = sdkCtx.EventManager().EmitTypedEvent(
&types.EventCreateMorseAccountState{
Height: sdkCtx.BlockHeight(),
Copy link
Member

Choose a reason for hiding this comment

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

Could you add some more details in this event given it'll only ever fired once (or a handful depending on how things evolve)?

E.g. Total amount of upokt transferred, total amount of accounts, etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should be fairly trivial to add the number of accounts.

I was already reluctant to do the hash computation on-chain due to concern about the CPU required to do so as the serialized state may be very large (tens of MB). Iterating over ~50K+ accounts to sum their amounts may take some time. I chose to avoid going down that rabbit hole. Happy to get out my shovel and hardhat if you think it's necessary.


"github.com/pokt-network/poktroll/x/migration/types"
)

func (k msgServer) CreateMorseAccountState(goCtx context.Context, msg *types.MsgCreateMorseAccountState) (*types.MsgCreateMorseAccountStateResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
func (k msgServer) CreateMorseAccountState(ctx context.Context, msg *types.MsgCreateMorseAccountState) (*types.MsgCreateMorseAccountStateResponse, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Consider multilining heaer for readability

Comment on lines +18 to +22
// NewMorseStateExportAndAccountStateBytes returns a serialized `MorseStateExport`
// and its corresponding `MorseAccountState`, populated dynamically with randomized
// account addresses, and monotonically increasing balances/stakes. For each account,
// one application and supplier are also added to the states.
// TODO_CONSIDERATION: Test/benchmark execution speed can be optimized by refactoring this to a pre-generate fixture.
Copy link
Member

Choose a reason for hiding this comment

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

If you use the "Code Cleaner" claude project I created, this is how it refactored the comments. Much easier to read.

Suggested change
// NewMorseStateExportAndAccountStateBytes returns a serialized `MorseStateExport`
// and its corresponding `MorseAccountState`, populated dynamically with randomized
// account addresses, and monotonically increasing balances/stakes. For each account,
// one application and supplier are also added to the states.
// TODO_CONSIDERATION: Test/benchmark execution speed can be optimized by refactoring this to a pre-generate fixture.
// NewMorseStateExportAndAccountStateBytes returns:
// - A serialized MorseStateExport
// - Its corresponding MorseAccountState
//
// The states are populated with:
// - Random account addresses
// - Monotonically increasing balances/stakes
// - One application per account
// - One supplier per account
//
// TODO_CONSIDERATION: Test/benchmark execution speed can be optimized by refactoring this to a pre-generate fixture.

Comment on lines +39 to +42
// NewMorseStateExportAndAccountState returns a `MorseStateExport` and its
// corresponding `MorseAccountState`, populated dynamically with randomized
// account addresses, and monotonically increasing balances/stakes. For each account,
// one application and supplier are also added to the states.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// NewMorseStateExportAndAccountState returns a `MorseStateExport` and its
// corresponding `MorseAccountState`, populated dynamically with randomized
// account addresses, and monotonically increasing balances/stakes. For each account,
// one application and supplier are also added to the states.
// NewMorseStateExportAndAccountState returns MorseStateExport and MorseAccountState
// structs populated with:
// - Random account addresses
// - Monotonically increasing balances/stakes
// - One application per account
// - One supplier per account
func NewMorseStateExportAndAccountState() (*types.MorseStateExport, *types.MorseAccountState)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
consensus-breaking IMPORTANT! If the PR with this tag is merged, next release WILL HAVE TO BE an upgrade. migration Morse to Shannon migration related work on-chain On-chain business logic
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

2 participants