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

[ADR] 0002 - Separate consensus and P2P IDs #33

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bryanchriswhite
Copy link
Contributor

@bryanchriswhite bryanchriswhite commented Apr 14, 2023

Summary

This pull request adds an Architecture Decision Record (ADR) for simplifying and consolidating node identity in our system by keeping consensus NodeId and P2P identity separate. The ADR explains the context, problem statement, decision drivers, considered options, and the decision outcome, along with the positive and negative consequences of the chosen option.

The chosen option is to keep consensus NodeId and P2P identity separate, as it prevents unintended interference between consensus and P2P layers while maintaining a clear separation of concerns.

Please review the ADR and provide feedback on:

  • The clarity of the problem statement and context
  • The thoroughness of the decision drivers and considered options
  • The appropriateness of the chosen option given the decision drivers
  • Any additional considerations that may have been overlooked
  • Any changes in formatting, grammar, or language for better readability

Related Issues

@bryanchriswhite bryanchriswhite added the architecture decision Related to architecture decision records (ADRs) label Apr 14, 2023
@bryanchriswhite bryanchriswhite self-assigned this Apr 14, 2023
@bryanchriswhite bryanchriswhite added p2p consensus Consensus specific changes labels Apr 14, 2023
@bryanchriswhite bryanchriswhite changed the base branch from main to docs/ADRs April 14, 2023 11:46
@bryanchriswhite bryanchriswhite force-pushed the docs/ADRs branch 2 times, most recently from 8e332c4 to 7e6934a Compare April 14, 2023 12:47
@bryanchriswhite bryanchriswhite force-pushed the docs/ADR0002 branch 2 times, most recently from 358fca0 to d061f8c Compare April 17, 2023 11:14
@bryanchriswhite bryanchriswhite changed the base branch from docs/ADRs to main April 17, 2023 11:14
@bryanchriswhite bryanchriswhite marked this pull request as ready for review April 17, 2023 11:19
@bryanchriswhite bryanchriswhite changed the title [ADR] 0002 - Simplifying Identity [ADR] 0002 - Separate consensus and P2P IDs Apr 17, 2023
@bryanchriswhite bryanchriswhite marked this pull request as draft April 18, 2023 17:34
@Olshansk Olshansk removed their request for review April 19, 2023 19:43
# ADR-0002: Separate consensus and P2P IDs

* Status: in review
* Deciders: Pocket Network team
Copy link
Member

Choose a reason for hiding this comment

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

Pocket Network Protocol Team

* Deciders: Pocket Network team
* Date: 2023-04-17

Technical Story: [Review Hotstuff Node IDs](https://github.com/pokt-network/pocket/issue/434)
Copy link
Member

Choose a reason for hiding this comment

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

See the PR for my updated template and lmk if you want to adopt it here (if we merge it).

Totally cool with not applying it retroactively, though.


## Context and Problem Statement

In the context of simplifying and consolidating node identity, facing the concern of multiple ID definitions, we decided to clarify the purpose of consensus NodeId and not consolidate it with P2P identity, to achieve a clearer separation of concerns, accepting potential confusion between different IDs, because this will prevent unintended interference between consensus and P2P layers.
Copy link
Member

Choose a reason for hiding this comment

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

Without examples, references or links, it's really hard to understand what the decision was actually entailing.

## Decision Drivers

* Clear separation of concerns between consensus and P2P layers
* Preventing unintended interference between different node identity types
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
* Preventing unintended interference between different node identity types
* Preventing unintended interference between different node identity types
* Maintenance, tracking and defining multiple type of IDs

@@ -0,0 +1,53 @@
# ADR-0002: Separate consensus and P2P IDs
Copy link
Member

Choose a reason for hiding this comment

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

This ADR does not define where/how Peer Identity is used and where/how NodeID is used.

* Bad, because it may lead to potential confusion between different node identity types
* Bad, because it requires maintaining multiple ID definitions

### Links
Copy link
Member

Choose a reason for hiding this comment

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

I did a bit more research in how we're using NodeID, and here's what I found.

How we define it (changes with every height where the valset is modified):

func NewActorMapper(validators []*coreTypes.Actor) *actorMapper {
	am := &actorMapper{
		valAddrToIdMap: make(ValAddrToIdMap, len(validators)),
		idToValAddrMap: make(IdToValAddrMap, len(validators)),
		validatorMap:   make(ValidatorMap, len(validators)),
	}

	valAddresses := make([]string, 0, len(validators))
	for _, val := range validators {
		addr := val.GetAddress()
		valAddresses = append(valAddresses, addr)
		am.validatorMap[addr] = val
	}
	sort.Strings(valAddresses)

	for i, addr := range valAddresses {
		nodeId := NodeId(i + 1) // TODO(#434): Improve the use of NodeIDs
		am.valAddrToIdMap[addr] = nodeId
		am.idToValAddrMap[nodeId] = addr
	}

	return am
}

How we use it (for deterministic round robin):

func (m *leaderElectionModule) electNextLeaderDeterministicRoundRobin(message *typesCons.HotstuffMessage) (typesCons.NodeId, error) {
	height := int64(message.Height)
	readCtx, err := m.GetBus().GetPersistenceModule().NewReadContext(height)
	if err != nil {
		return typesCons.NodeId(0), err
	}
	defer readCtx.Release()

	vals, err := readCtx.GetAllValidators(height)
	if err != nil {
		return typesCons.NodeId(0), err
	}

	value := int64(message.Height) + int64(message.Round) + int64(message.Step) - 1
	numVals := int64(len(vals))

	return typesCons.NodeId(value%numVals + 1), nil
}

If we leverage the PeerID, we can just use the sorting mechanism there and avoid a separate "NodeId".

It feels like it would cause less cognitive load for new entrants to the codebase. Wdyt?

@Olshansk
Copy link
Member

@bryanchriswhite wanted to follow up on my comments in this ADR.

@bryanchriswhite bryanchriswhite marked this pull request as draft May 19, 2023 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
architecture decision Related to architecture decision records (ADRs) consensus Consensus specific changes p2p
Projects
Status: In Review
Development

Successfully merging this pull request may close these issues.

2 participants