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

Raft consensus for lotus nodes in a cluster #9294

Merged

Conversation

shrenujbansal
Copy link
Contributor

Related Issues

#9130

Proposed Changes

Adding raft consensus to lotus nodes to maintain consistent state for nonces and messages being published to the lotus node

Additional Info

Checklist

Before you mark the PR ready for review, please make sure that:

  • All commits have a clear commit message.
  • The PR title is in the form of of <PR type>: <area>: <change being made>
    • example: fix: mempool: Introduce a cache for valid signatures
    • PR type: fix, feat, INTERFACE BREAKING CHANGE, CONSENSUS BREAKING, build, chore, ci, docs,perf, refactor, revert, style, test
    • area: api, chain, state, vm, data transfer, market, mempool, message, block production, multisig, networking, paychan, proving, sealing, wallet, deps
  • This PR has tests for new functionality or change in behaviour
  • If new user-facing features are introduced, clear usage guidelines and / or documentation updates should be included in https://lotus.filecoin.io or Discussion Tutorials.
  • CI is green

@shrenujbansal shrenujbansal requested a review from a team as a code owner September 12, 2022 20:04
@shrenujbansal shrenujbansal force-pushed the sbansal/nonce-coordination-and-consensus-for-chain-nodes branch from 1dc9115 to 58013e8 Compare September 12, 2022 20:08
@shrenujbansal shrenujbansal force-pushed the sbansal/nonce-coordination-and-consensus-for-chain-nodes branch from 58013e8 to 8f1b1bb Compare September 12, 2022 20:10
@magik6k magik6k marked this pull request as draft September 16, 2022 10:51
Copy link
Contributor

@magik6k magik6k left a comment

Choose a reason for hiding this comment

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

First pass, doesn't feel like there's that much left to do, mostly cleaning up / making stuff more robust.

  • Looks like a devnet genesis (devgen.car) got committed by accident; Given that it's a little bit we'll need to make sure it's removed from all commits in the PR to not carry it with git history after merging

localnet.json Outdated Show resolved Hide resolved
chain/messagesigner/messagesigner.go Outdated Show resolved Hide resolved
chain/messagesigner/messagesigner.go Outdated Show resolved Hide resolved
chain/messagesigner/messagesigner.go Outdated Show resolved Hide resolved
chain/messagesigner/messagesigner.go Outdated Show resolved Hide resolved
node/config/types.go Outdated Show resolved Hide resolved
node/config/types.go Outdated Show resolved Hide resolved
node/modules/rpc.go Outdated Show resolved Hide resolved
node/modules/rpc.go Outdated Show resolved Hide resolved
node/modules/rpc.go Outdated Show resolved Hide resolved
@magik6k magik6k mentioned this pull request Sep 27, 2022
5 tasks
chain/messagesigner/messagesigner.go Outdated Show resolved Hide resolved
chain/messagesigner/messagesigner.go Outdated Show resolved Hide resolved
chain/messagesigner/messagesigner.go Outdated Show resolved Hide resolved
Comment on lines 45 to 51
func (ms *MessageSignerConsensus) RedirectToLeader(ctx context.Context, method string, arg interface{}, ret interface{}) (bool, error) {
ok, err := ms.consensus.RedirectToLeader(method, arg, ret.(*types.SignedMessage))
if err != nil {
return ok, err
}
return ok, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we drop this method?

Suggested change
func (ms *MessageSignerConsensus) RedirectToLeader(ctx context.Context, method string, arg interface{}, ret interface{}) (bool, error) {
ok, err := ms.consensus.RedirectToLeader(method, arg, ret.(*types.SignedMessage))
if err != nil {
return ok, err
}
return ok, nil
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, this is needed to be called in MpoolPushMessage

chain/messagesigner/messagesigner_consensus.go Outdated Show resolved Hide resolved
cli/util/api.go Outdated Show resolved Hide resolved
cli/util/api.go Show resolved Hide resolved
cli/util/apiinfo.go Outdated Show resolved Hide resolved
documentation/en/default-lotus-config.toml Outdated Show resolved Hide resolved
node/modules/storageminer.go Outdated Show resolved Hide resolved
@shrenujbansal shrenujbansal marked this pull request as ready for review October 20, 2022 14:28
@shrenujbansal shrenujbansal changed the title WIP: Raft consensus for lotus nodes in a cluster Raft consensus for lotus nodes in a cluster Nov 11, 2022
Copy link
Contributor

@magik6k magik6k left a comment

Choose a reason for hiding this comment

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

Looks like there is a commit updating extern/filecoin-ffi by accident

Comment on lines +343 to +344
type NonceMapType map[address.Address]uint64
type MsgUuidMapType map[uuid.UUID]*types.SignedMessage
Copy link
Contributor

Choose a reason for hiding this comment

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

Not needed to land this PR, but if we wanted to be fancy, we could write a generic helper type for maps with typed keys.

chain/messagepool/provider.go Outdated Show resolved Hide resolved
chain/messagesigner/messagesigner.go Outdated Show resolved Hide resolved
ds dtypes.MetadataDS,
consensus *consensus.Consensus) *MessageSignerConsensus {

ds = namespace.Wrap(ds, datastore.NewKey("/message-signer-consensus/"))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a different prefix than the one used in non-consensus messagesigner, but I guess that's what we want.

I'm just not 100% sure that we actually need this to be a different prefix.

documentation/en/default-lotus-config.toml Outdated Show resolved Hide resolved
lib/consensus/raft/consensus.go Outdated Show resolved Hide resolved
lib/consensus/raft/consensus.go Outdated Show resolved Hide resolved
lib/consensus/raft/consensus.go Outdated Show resolved Hide resolved
lib/consensus/raft/raft.go Outdated Show resolved Hide resolved
lib/consensus/raft/raft.go Outdated Show resolved Hide resolved
@@ -667,7 +668,7 @@ func (mp *MessagePool) verifyMsgBeforeAdd(ctx context.Context, m *types.SignedMe
return publish, nil
}

func (mp *MessagePool) Push(ctx context.Context, m *types.SignedMessage) (cid.Cid, error) {
func (mp *MessagePool) Push(ctx context.Context, m *types.SignedMessage, publish bool) (cid.Cid, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see a similar change for PushUntrusted. Is that intentional?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, could you leave a clear comment on what exactly this bool does?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We shouldn't need it for PushUntrusted since its not used in syncing the message pool. I think this API should really be folded back into Push itself and add a untrusted param to it

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I definitely agree :)

@magik6k
Copy link
Contributor

magik6k commented Nov 15, 2022

Dependency diff if anyone else wants to review: https://gist.github.com/magik6k/ada79bebc4f5ccf3078d72f6513a49e2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants