Skip to content

Commit

Permalink
Remove lists from Chits messages (ava-labs#1412)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph committed Jun 2, 2023
1 parent 2cd81c6 commit bdfa043
Show file tree
Hide file tree
Showing 23 changed files with 189 additions and 232 deletions.
16 changes: 6 additions & 10 deletions message/inbound_msg_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,22 +243,18 @@ func InboundPullQuery(
func InboundChits(
chainID ids.ID,
requestID uint32,
preferredContainerIDs []ids.ID,
acceptedContainerIDs []ids.ID,
preferredID ids.ID,
acceptedID ids.ID,
nodeID ids.NodeID,
) InboundMessage {
preferredContainerIDBytes := make([][]byte, len(preferredContainerIDs))
encodeIDs(preferredContainerIDs, preferredContainerIDBytes)
acceptedContainerIDBytes := make([][]byte, len(acceptedContainerIDs))
encodeIDs(acceptedContainerIDs, acceptedContainerIDBytes)
return &inboundMessage{
nodeID: nodeID,
op: ChitsOp,
message: &p2p.Chits{
ChainId: chainID[:],
RequestId: requestID,
PreferredContainerIds: preferredContainerIDBytes,
AcceptedContainerIds: acceptedContainerIDBytes,
ChainId: chainID[:],
RequestId: requestID,
PreferredId: preferredID[:],
AcceptedId: acceptedID[:],
},
expiration: mockable.MaxTime,
}
Expand Down
18 changes: 4 additions & 14 deletions message/inbound_msg_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ func TestInboundMsgBuilder(t *testing.T) {
msg := InboundChits(
chainID,
requestID,
containerIDs,
acceptedContainerIDs,
containerIDs[0],
acceptedContainerIDs[0],
nodeID,
)

Expand All @@ -339,18 +339,8 @@ func TestInboundMsgBuilder(t *testing.T) {
innerMsg := msg.Message().(*p2p.Chits)
require.Equal(chainID[:], innerMsg.ChainId)
require.Equal(requestID, innerMsg.RequestId)
containerIDsBytes := make([][]byte, len(containerIDs))
for i, id := range containerIDs {
id := id
containerIDsBytes[i] = id[:]
}
require.Equal(containerIDsBytes, innerMsg.PreferredContainerIds)
acceptedContainerIDsBytes := make([][]byte, len(acceptedContainerIDs))
for i, id := range acceptedContainerIDs {
id := id
acceptedContainerIDsBytes[i] = id[:]
}
require.Equal(acceptedContainerIDsBytes, innerMsg.AcceptedContainerIds)
require.Equal(containerIDs[0][:], innerMsg.PreferredId)
require.Equal(acceptedContainerIDs[0][:], innerMsg.AcceptedId)
},
)

Expand Down
6 changes: 3 additions & 3 deletions message/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,9 +672,9 @@ func TestMessage(t *testing.T) {
msg: &p2p.Message{
Message: &p2p.Message_Chits{
Chits: &p2p.Chits{
ChainId: testID[:],
RequestId: 1,
PreferredContainerIds: [][]byte{testID[:], testID[:]},
ChainId: testID[:],
RequestId: 1,
PreferredId: testID[:],
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion message/mock_outbound_message_builder.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 8 additions & 12 deletions message/outbound_msg_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ type OutboundMsgBuilder interface {
Chits(
chainID ids.ID,
requestID uint32,
preferredContainerIDs []ids.ID,
acceptedContainerIDs []ids.ID,
preferredID ids.ID,
acceptedID ids.ID,
) (OutboundMessage, error)

AppRequest(
Expand Down Expand Up @@ -608,21 +608,17 @@ func (b *outMsgBuilder) PullQuery(
func (b *outMsgBuilder) Chits(
chainID ids.ID,
requestID uint32,
preferredContainerIDs []ids.ID,
acceptedContainerIDs []ids.ID,
preferredID ids.ID,
acceptedID ids.ID,
) (OutboundMessage, error) {
preferredContainerIDBytes := make([][]byte, len(preferredContainerIDs))
encodeIDs(preferredContainerIDs, preferredContainerIDBytes)
acceptedContainerIDBytes := make([][]byte, len(acceptedContainerIDs))
encodeIDs(acceptedContainerIDs, acceptedContainerIDBytes)
return b.builder.createOutbound(
&p2p.Message{
Message: &p2p.Message_Chits{
Chits: &p2p.Chits{
ChainId: chainID[:],
RequestId: requestID,
PreferredContainerIds: preferredContainerIDBytes,
AcceptedContainerIds: acceptedContainerIDBytes,
ChainId: chainID[:],
RequestId: requestID,
PreferredId: preferredID[:],
AcceptedId: acceptedID[:],
},
},
},
Expand Down
21 changes: 10 additions & 11 deletions proto/p2p/p2p.proto
Original file line number Diff line number Diff line change
Expand Up @@ -318,23 +318,22 @@ message PullQuery {
EngineType engine_type = 5;
}

// Message that contains the votes/preferences of the local node,
// in response to "push_query" or "pull_query" (e.g., preferred frontier).
// Message that contains the votes/preferences of the node. It is sent in
// response to a "push_query" or "pull_query" request.
//
// On receiving "chits", the engine issues those preferred containers of vertices/blocks
// to the consensus. If the received container is not found, it responds back with
// "get" message to fetch the missing container from the remote peer.
// Upon receiving "chits", the engine will attempt to issue the preferred block
// into consensus. If the referenced block is not locally available, the engine
// will respond with a "get" message to fetch the missing block from the remote
// peer.
message Chits {
reserved 5; // Until Cortina upgrade is activated

bytes chain_id = 1;
uint32 request_id = 2;
// Represents the current preferred frontier.
// TODO: Remove `repeated` once all chains are running Snowman.
repeated bytes preferred_container_ids = 3;
// Represents the current accepted frontier.
// TODO: Remove `repeated` once all chains are running Snowman.
repeated bytes accepted_container_ids = 4;
// Represents the current preferred block.
bytes preferred_id = 3;
// Represents the last accepted block.
bytes accepted_id = 4;
}

message AppRequest {
Expand Down
98 changes: 47 additions & 51 deletions proto/pb/p2p/p2p.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions snow/engine/common/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ type ChitsHandler interface {
ctx context.Context,
validatorID ids.NodeID,
requestID uint32,
preferredContainerIDs []ids.ID,
acceptedContainerIDs []ids.ID,
preferredID ids.ID,
acceptedID ids.ID,
) error

// Notify this engine that a query it issued has failed.
Expand Down
2 changes: 1 addition & 1 deletion snow/engine/common/mock_sender.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion snow/engine/common/no_ops_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,14 @@ func NewNoOpChitsHandler(log logging.Logger) ChitsHandler {
return &noOpChitsHandler{log: log}
}

func (nop *noOpChitsHandler) Chits(_ context.Context, nodeID ids.NodeID, requestID uint32, _, _ []ids.ID) error {
func (nop *noOpChitsHandler) Chits(_ context.Context, nodeID ids.NodeID, requestID uint32, preferredID, acceptedID ids.ID) error {
nop.log.Debug("dropping request",
zap.String("reason", "unhandled by this gear"),
zap.Stringer("messageOp", message.ChitsOp),
zap.Stringer("nodeID", nodeID),
zap.Uint32("requestID", requestID),
zap.Stringer("preferredID", preferredID),
zap.Stringer("acceptedID", acceptedID),
)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion snow/engine/common/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ type QuerySender interface {
SendPullQuery(ctx context.Context, nodeIDs set.Set[ids.NodeID], requestID uint32, containerID ids.ID)

// Send chits to the specified node
SendChits(ctx context.Context, nodeID ids.NodeID, requestID uint32, votes []ids.ID, accepted []ids.ID)
SendChits(ctx context.Context, nodeID ids.NodeID, requestID uint32, preferredID ids.ID, acceptedID ids.ID)
}

// Gossiper defines how a consensus engine gossips a container on the accepted
Expand Down
6 changes: 3 additions & 3 deletions snow/engine/common/test_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ type EngineTest struct {
PutF, PushQueryF func(ctx context.Context, nodeID ids.NodeID, requestID uint32, container []byte) error
AncestorsF func(ctx context.Context, nodeID ids.NodeID, requestID uint32, containers [][]byte) error
AcceptedFrontierF, GetAcceptedF, AcceptedF func(ctx context.Context, nodeID ids.NodeID, requestID uint32, preferredIDs []ids.ID) error
ChitsF func(ctx context.Context, nodeID ids.NodeID, requestID uint32, preferredIDs []ids.ID, acceptedIDs []ids.ID) error
ChitsF func(ctx context.Context, nodeID ids.NodeID, requestID uint32, preferredID ids.ID, acceptedID ids.ID) error
GetStateSummaryFrontierF, GetStateSummaryFrontierFailedF, GetAcceptedStateSummaryFailedF,
GetAcceptedFrontierF, GetFailedF, GetAncestorsFailedF,
QueryFailedF, GetAcceptedFrontierFailedF, GetAcceptedFailedF func(ctx context.Context, nodeID ids.NodeID, requestID uint32) error
Expand Down Expand Up @@ -631,9 +631,9 @@ func (e *EngineTest) AppGossip(ctx context.Context, nodeID ids.NodeID, msg []byt
return errAppGossip
}

func (e *EngineTest) Chits(ctx context.Context, nodeID ids.NodeID, requestID uint32, preferredIDs []ids.ID, acceptedIDs []ids.ID) error {
func (e *EngineTest) Chits(ctx context.Context, nodeID ids.NodeID, requestID uint32, preferredID ids.ID, acceptedID ids.ID) error {
if e.ChitsF != nil {
return e.ChitsF(ctx, nodeID, requestID, preferredIDs, acceptedIDs)
return e.ChitsF(ctx, nodeID, requestID, preferredID, acceptedID)
}
if !e.CantChits {
return nil
Expand Down

0 comments on commit bdfa043

Please sign in to comment.