diff --git a/message/inbound_msg_builder.go b/message/inbound_msg_builder.go index 1cc1edcd8670..c52e8e0afc47 100644 --- a/message/inbound_msg_builder.go +++ b/message/inbound_msg_builder.go @@ -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, } diff --git a/message/inbound_msg_builder_test.go b/message/inbound_msg_builder_test.go index 068ce857f901..951693f3e80b 100644 --- a/message/inbound_msg_builder_test.go +++ b/message/inbound_msg_builder_test.go @@ -327,8 +327,8 @@ func TestInboundMsgBuilder(t *testing.T) { msg := InboundChits( chainID, requestID, - containerIDs, - acceptedContainerIDs, + containerIDs[0], + acceptedContainerIDs[0], nodeID, ) @@ -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) }, ) diff --git a/message/messages_test.go b/message/messages_test.go index d0beaa6fc67b..33ee2ca35428 100644 --- a/message/messages_test.go +++ b/message/messages_test.go @@ -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[:], }, }, }, diff --git a/message/mock_outbound_message_builder.go b/message/mock_outbound_message_builder.go index 5d34b6ba3bb9..d8b1b46fa912 100644 --- a/message/mock_outbound_message_builder.go +++ b/message/mock_outbound_message_builder.go @@ -146,7 +146,7 @@ func (mr *MockOutboundMsgBuilderMockRecorder) AppResponse(arg0, arg1, arg2 inter } // Chits mocks base method. -func (m *MockOutboundMsgBuilder) Chits(arg0 ids.ID, arg1 uint32, arg2, arg3 []ids.ID) (OutboundMessage, error) { +func (m *MockOutboundMsgBuilder) Chits(arg0 ids.ID, arg1 uint32, arg2, arg3 ids.ID) (OutboundMessage, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Chits", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(OutboundMessage) diff --git a/message/outbound_msg_builder.go b/message/outbound_msg_builder.go index 330df8f794ce..828bda0d5b40 100644 --- a/message/outbound_msg_builder.go +++ b/message/outbound_msg_builder.go @@ -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( @@ -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[:], }, }, }, diff --git a/proto/p2p/p2p.proto b/proto/p2p/p2p.proto index 86d0505330b5..f5726512f262 100644 --- a/proto/p2p/p2p.proto +++ b/proto/p2p/p2p.proto @@ -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 { diff --git a/proto/pb/p2p/p2p.pb.go b/proto/pb/p2p/p2p.pb.go index ac74a80f3a3d..31cdbf09b1dd 100644 --- a/proto/pb/p2p/p2p.pb.go +++ b/proto/pb/p2p/p2p.pb.go @@ -2077,12 +2077,13 @@ func (x *PullQuery) GetEngineType() EngineType { return EngineType_ENGINE_TYPE_UNSPECIFIED } -// 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. type Chits struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -2090,12 +2091,10 @@ type Chits struct { ChainId []byte `protobuf:"bytes,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` RequestId uint32 `protobuf:"varint,2,opt,name=request_id,json=requestId,proto3" json:"request_id,omitempty"` - // Represents the current preferred frontier. - // TODO: Remove `repeated` once all chains are running Snowman. - PreferredContainerIds [][]byte `protobuf:"bytes,3,rep,name=preferred_container_ids,json=preferredContainerIds,proto3" json:"preferred_container_ids,omitempty"` - // Represents the current accepted frontier. - // TODO: Remove `repeated` once all chains are running Snowman. - AcceptedContainerIds [][]byte `protobuf:"bytes,4,rep,name=accepted_container_ids,json=acceptedContainerIds,proto3" json:"accepted_container_ids,omitempty"` + // Represents the current preferred block. + PreferredId []byte `protobuf:"bytes,3,opt,name=preferred_id,json=preferredId,proto3" json:"preferred_id,omitempty"` + // Represents the last accepted block. + AcceptedId []byte `protobuf:"bytes,4,opt,name=accepted_id,json=acceptedId,proto3" json:"accepted_id,omitempty"` } func (x *Chits) Reset() { @@ -2144,16 +2143,16 @@ func (x *Chits) GetRequestId() uint32 { return 0 } -func (x *Chits) GetPreferredContainerIds() [][]byte { +func (x *Chits) GetPreferredId() []byte { if x != nil { - return x.PreferredContainerIds + return x.PreferredId } return nil } -func (x *Chits) GetAcceptedContainerIds() [][]byte { +func (x *Chits) GetAcceptedId() []byte { if x != nil { - return x.AcceptedContainerIds + return x.AcceptedId } return nil } @@ -2620,47 +2619,44 @@ var file_p2p_p2p_proto_rawDesc = []byte{ 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x12, 0x30, 0x0a, 0x0b, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0f, 0x2e, 0x70, 0x32, 0x70, 0x2e, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, - 0x52, 0x0a, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x22, 0xb5, 0x01, 0x0a, + 0x52, 0x0a, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x22, 0x8b, 0x01, 0x0a, 0x05, 0x43, 0x68, 0x69, 0x74, 0x73, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, - 0x12, 0x36, 0x0a, 0x17, 0x70, 0x72, 0x65, 0x66, 0x65, 0x72, 0x72, 0x65, 0x64, 0x5f, 0x63, 0x6f, - 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, - 0x0c, 0x52, 0x15, 0x70, 0x72, 0x65, 0x66, 0x65, 0x72, 0x72, 0x65, 0x64, 0x43, 0x6f, 0x6e, 0x74, - 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x73, 0x12, 0x34, 0x0a, 0x16, 0x61, 0x63, 0x63, 0x65, - 0x70, 0x74, 0x65, 0x64, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, - 0x64, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x14, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, - 0x65, 0x64, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x73, 0x4a, 0x04, - 0x08, 0x05, 0x10, 0x06, 0x22, 0x7f, 0x0a, 0x0a, 0x41, 0x70, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, - 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, - 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, - 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x61, 0x70, 0x70, 0x5f, - 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x61, 0x70, 0x70, - 0x42, 0x79, 0x74, 0x65, 0x73, 0x22, 0x64, 0x0a, 0x0b, 0x41, 0x70, 0x70, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, - 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1b, - 0x0a, 0x09, 0x61, 0x70, 0x70, 0x5f, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, - 0x0c, 0x52, 0x08, 0x61, 0x70, 0x70, 0x42, 0x79, 0x74, 0x65, 0x73, 0x22, 0x43, 0x0a, 0x09, 0x41, - 0x70, 0x70, 0x47, 0x6f, 0x73, 0x73, 0x69, 0x70, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, + 0x12, 0x21, 0x0a, 0x0c, 0x70, 0x72, 0x65, 0x66, 0x65, 0x72, 0x72, 0x65, 0x64, 0x5f, 0x69, 0x64, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x70, 0x72, 0x65, 0x66, 0x65, 0x72, 0x72, 0x65, + 0x64, 0x49, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x5f, + 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, + 0x65, 0x64, 0x49, 0x64, 0x4a, 0x04, 0x08, 0x05, 0x10, 0x06, 0x22, 0x7f, 0x0a, 0x0a, 0x41, 0x70, + 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, - 0x6e, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x61, 0x70, 0x70, 0x5f, 0x62, 0x79, 0x74, 0x65, 0x73, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x61, 0x70, 0x70, 0x42, 0x79, 0x74, 0x65, 0x73, - 0x2a, 0x5d, 0x0a, 0x0a, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1b, - 0x0a, 0x17, 0x45, 0x4e, 0x47, 0x49, 0x4e, 0x45, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x55, 0x4e, - 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x19, 0x0a, 0x15, 0x45, - 0x4e, 0x47, 0x49, 0x4e, 0x45, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x41, 0x56, 0x41, 0x4c, 0x41, - 0x4e, 0x43, 0x48, 0x45, 0x10, 0x01, 0x12, 0x17, 0x0a, 0x13, 0x45, 0x4e, 0x47, 0x49, 0x4e, 0x45, - 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x53, 0x4e, 0x4f, 0x57, 0x4d, 0x41, 0x4e, 0x10, 0x02, 0x42, - 0x2e, 0x5a, 0x2c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x76, - 0x61, 0x2d, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x61, 0x76, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x68, 0x65, - 0x67, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x62, 0x2f, 0x70, 0x32, 0x70, 0x62, - 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, + 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x1b, + 0x0a, 0x09, 0x61, 0x70, 0x70, 0x5f, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, + 0x0c, 0x52, 0x08, 0x61, 0x70, 0x70, 0x42, 0x79, 0x74, 0x65, 0x73, 0x22, 0x64, 0x0a, 0x0b, 0x41, + 0x70, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, + 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, + 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x61, 0x70, 0x70, 0x5f, 0x62, 0x79, 0x74, 0x65, + 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x61, 0x70, 0x70, 0x42, 0x79, 0x74, 0x65, + 0x73, 0x22, 0x43, 0x0a, 0x09, 0x41, 0x70, 0x70, 0x47, 0x6f, 0x73, 0x73, 0x69, 0x70, 0x12, 0x19, + 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, + 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x61, 0x70, 0x70, + 0x5f, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x61, 0x70, + 0x70, 0x42, 0x79, 0x74, 0x65, 0x73, 0x2a, 0x5d, 0x0a, 0x0a, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, + 0x54, 0x79, 0x70, 0x65, 0x12, 0x1b, 0x0a, 0x17, 0x45, 0x4e, 0x47, 0x49, 0x4e, 0x45, 0x5f, 0x54, + 0x59, 0x50, 0x45, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, + 0x00, 0x12, 0x19, 0x0a, 0x15, 0x45, 0x4e, 0x47, 0x49, 0x4e, 0x45, 0x5f, 0x54, 0x59, 0x50, 0x45, + 0x5f, 0x41, 0x56, 0x41, 0x4c, 0x41, 0x4e, 0x43, 0x48, 0x45, 0x10, 0x01, 0x12, 0x17, 0x0a, 0x13, + 0x45, 0x4e, 0x47, 0x49, 0x4e, 0x45, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x53, 0x4e, 0x4f, 0x57, + 0x4d, 0x41, 0x4e, 0x10, 0x02, 0x42, 0x2e, 0x5a, 0x2c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, + 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x76, 0x61, 0x2d, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x61, 0x76, 0x61, + 0x6c, 0x61, 0x6e, 0x63, 0x68, 0x65, 0x67, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, + 0x62, 0x2f, 0x70, 0x32, 0x70, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/snow/engine/common/engine.go b/snow/engine/common/engine.go index 142351b2ea6b..6466a66874b8 100644 --- a/snow/engine/common/engine.go +++ b/snow/engine/common/engine.go @@ -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. diff --git a/snow/engine/common/mock_sender.go b/snow/engine/common/mock_sender.go index c599077dd881..6eccda2e6232 100644 --- a/snow/engine/common/mock_sender.go +++ b/snow/engine/common/mock_sender.go @@ -159,7 +159,7 @@ func (mr *MockSenderMockRecorder) SendAppResponse(arg0, arg1, arg2, arg3 interfa } // SendChits mocks base method. -func (m *MockSender) SendChits(arg0 context.Context, arg1 ids.NodeID, arg2 uint32, arg3, arg4 []ids.ID) { +func (m *MockSender) SendChits(arg0 context.Context, arg1 ids.NodeID, arg2 uint32, arg3, arg4 ids.ID) { m.ctrl.T.Helper() m.ctrl.Call(m, "SendChits", arg0, arg1, arg2, arg3, arg4) } diff --git a/snow/engine/common/no_ops_handlers.go b/snow/engine/common/no_ops_handlers.go index de3c98175484..06c30a8bb097 100644 --- a/snow/engine/common/no_ops_handlers.go +++ b/snow/engine/common/no_ops_handlers.go @@ -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 } diff --git a/snow/engine/common/sender.go b/snow/engine/common/sender.go index 1c657daa3555..a8d9f88390c8 100644 --- a/snow/engine/common/sender.go +++ b/snow/engine/common/sender.go @@ -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 diff --git a/snow/engine/common/test_engine.go b/snow/engine/common/test_engine.go index 6645efad33e0..ade1d6e00455 100644 --- a/snow/engine/common/test_engine.go +++ b/snow/engine/common/test_engine.go @@ -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 @@ -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 diff --git a/snow/engine/common/test_sender.go b/snow/engine/common/test_sender.go index 0a32dcc00ea2..e1d797cf13a9 100644 --- a/snow/engine/common/test_sender.go +++ b/snow/engine/common/test_sender.go @@ -53,7 +53,7 @@ type SenderTest struct { SendAncestorsF func(context.Context, ids.NodeID, uint32, [][]byte) SendPushQueryF func(context.Context, set.Set[ids.NodeID], uint32, []byte) SendPullQueryF func(context.Context, set.Set[ids.NodeID], uint32, ids.ID) - SendChitsF func(context.Context, ids.NodeID, uint32, []ids.ID, []ids.ID) + SendChitsF func(context.Context, ids.NodeID, uint32, ids.ID, ids.ID) SendGossipF func(context.Context, []byte) SendAppRequestF func(context.Context, set.Set[ids.NodeID], uint32, []byte) error SendAppResponseF func(context.Context, ids.NodeID, uint32, []byte) error @@ -263,9 +263,9 @@ func (s *SenderTest) SendPullQuery(ctx context.Context, vdrs set.Set[ids.NodeID] // SendChits calls SendChitsF if it was initialized. If it wasn't initialized // and this function shouldn't be called and testing was initialized, then // testing will fail. -func (s *SenderTest) SendChits(ctx context.Context, vdr ids.NodeID, requestID uint32, votes []ids.ID, accepted []ids.ID) { +func (s *SenderTest) SendChits(ctx context.Context, vdr ids.NodeID, requestID uint32, preferredID ids.ID, acceptedID ids.ID) { if s.SendChitsF != nil { - s.SendChitsF(ctx, vdr, requestID, votes, accepted) + s.SendChitsF(ctx, vdr, requestID, preferredID, acceptedID) } else if s.CantSendChits && s.T != nil { s.T.Fatalf("Unexpectedly called SendChits") } diff --git a/snow/engine/common/traced_engine.go b/snow/engine/common/traced_engine.go index f2e723a4d176..73bb02efc5cb 100644 --- a/snow/engine/common/traced_engine.go +++ b/snow/engine/common/traced_engine.go @@ -243,16 +243,16 @@ func (e *tracedEngine) PushQuery(ctx context.Context, nodeID ids.NodeID, request return e.engine.PushQuery(ctx, nodeID, requestID, container) } -func (e *tracedEngine) Chits(ctx context.Context, nodeID ids.NodeID, requestID uint32, preferredIDs []ids.ID, acceptedIDs []ids.ID) error { +func (e *tracedEngine) Chits(ctx context.Context, nodeID ids.NodeID, requestID uint32, preferredID ids.ID, acceptedID ids.ID) error { ctx, span := e.tracer.Start(ctx, "tracedEngine.Chits", oteltrace.WithAttributes( attribute.Stringer("nodeID", nodeID), attribute.Int64("requestID", int64(requestID)), - attribute.Int("numPreferredIDs", len(preferredIDs)), - attribute.Int("numAcceptedIDs", len(acceptedIDs)), + attribute.Stringer("preferredID", preferredID), + attribute.Stringer("acceptedID", acceptedID), )) defer span.End() - return e.engine.Chits(ctx, nodeID, requestID, preferredIDs, acceptedIDs) + return e.engine.Chits(ctx, nodeID, requestID, preferredID, acceptedID) } func (e *tracedEngine) QueryFailed(ctx context.Context, nodeID ids.NodeID, requestID uint32) error { diff --git a/snow/engine/common/tracker/accepted.go b/snow/engine/common/tracker/accepted.go index 4b3f0f1ac783..0be64bc9035e 100644 --- a/snow/engine/common/tracker/accepted.go +++ b/snow/engine/common/tracker/accepted.go @@ -9,6 +9,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/set" ) var _ Accepted = (*accepted)(nil) @@ -16,24 +17,23 @@ var _ Accepted = (*accepted)(nil) type Accepted interface { validators.SetCallbackListener - // SetAcceptedFrontier updates the latest frontier for [nodeID] to - // [frontier]. If [nodeID] is not currently a validator, this is a noop. - SetAcceptedFrontier(nodeID ids.NodeID, frontier []ids.ID) - // AcceptedFrontier returns the latest known accepted frontier of [nodeID]. - // If [nodeID]'s last accepted frontier is unknown, an empty slice will be - // returned. - AcceptedFrontier(nodeID ids.NodeID) []ids.ID + // SetLastAccepted updates the latest accepted block for [nodeID] to + // [blockID]. If [nodeID] is not currently a validator, this is a noop. + SetLastAccepted(nodeID ids.NodeID, blockID ids.ID) + // LastAccepted returns the latest known accepted block of [nodeID]. If + // [nodeID]'s last accepted block was never unknown, false will be returned. + LastAccepted(nodeID ids.NodeID) (ids.ID, bool) } type accepted struct { - lock sync.RWMutex - // frontier contains an entry for all current validators - frontier map[ids.NodeID][]ids.ID + lock sync.RWMutex + validators set.Set[ids.NodeID] + frontier map[ids.NodeID]ids.ID } func NewAccepted() Accepted { return &accepted{ - frontier: make(map[ids.NodeID][]ids.ID), + frontier: make(map[ids.NodeID]ids.ID), } } @@ -41,30 +41,32 @@ func (a *accepted) OnValidatorAdded(nodeID ids.NodeID, _ *bls.PublicKey, _ ids.I a.lock.Lock() defer a.lock.Unlock() - a.frontier[nodeID] = nil + a.validators.Add(nodeID) } func (a *accepted) OnValidatorRemoved(nodeID ids.NodeID, _ uint64) { a.lock.Lock() defer a.lock.Unlock() + a.validators.Remove(nodeID) delete(a.frontier, nodeID) } func (*accepted) OnValidatorWeightChanged(_ ids.NodeID, _, _ uint64) {} -func (a *accepted) SetAcceptedFrontier(nodeID ids.NodeID, frontier []ids.ID) { +func (a *accepted) SetLastAccepted(nodeID ids.NodeID, frontier ids.ID) { a.lock.Lock() defer a.lock.Unlock() - if _, ok := a.frontier[nodeID]; ok { + if a.validators.Contains(nodeID) { a.frontier[nodeID] = frontier } } -func (a *accepted) AcceptedFrontier(nodeID ids.NodeID) []ids.ID { +func (a *accepted) LastAccepted(nodeID ids.NodeID) (ids.ID, bool) { a.lock.RLock() defer a.lock.RUnlock() - return a.frontier[nodeID] + acceptedID, ok := a.frontier[nodeID] + return acceptedID, ok } diff --git a/snow/engine/common/tracker/accepted_test.go b/snow/engine/common/tracker/accepted_test.go index dbd5faf89808..7bb617d789f9 100644 --- a/snow/engine/common/tracker/accepted_test.go +++ b/snow/engine/common/tracker/accepted_test.go @@ -15,27 +15,35 @@ func TestAccepted(t *testing.T) { require := require.New(t) nodeID := ids.GenerateTestNodeID() - frontier0 := []ids.ID{ids.GenerateTestID()} - frontier1 := []ids.ID{ids.GenerateTestID()} + blkID0 := ids.GenerateTestID() + blkID1 := ids.GenerateTestID() a := NewAccepted() - require.Empty(a.AcceptedFrontier(nodeID)) + _, ok := a.LastAccepted(nodeID) + require.False(ok) - a.SetAcceptedFrontier(nodeID, frontier0) - require.Empty(a.AcceptedFrontier(nodeID)) + a.SetLastAccepted(nodeID, blkID0) + _, ok = a.LastAccepted(nodeID) + require.False(ok) a.OnValidatorAdded(nodeID, nil, ids.GenerateTestID(), 1) - require.Empty(a.AcceptedFrontier(nodeID)) + _, ok = a.LastAccepted(nodeID) + require.False(ok) - a.SetAcceptedFrontier(nodeID, frontier0) - require.Equal(frontier0, a.AcceptedFrontier(nodeID)) + a.SetLastAccepted(nodeID, blkID0) + blkID, ok := a.LastAccepted(nodeID) + require.True(ok) + require.Equal(blkID0, blkID) - a.SetAcceptedFrontier(nodeID, frontier1) - require.Equal(frontier1, a.AcceptedFrontier(nodeID)) + a.SetLastAccepted(nodeID, blkID1) + blkID, ok = a.LastAccepted(nodeID) + require.True(ok) + require.Equal(blkID1, blkID) a.OnValidatorRemoved(nodeID, 1) - require.Empty(a.AcceptedFrontier(nodeID)) + _, ok = a.LastAccepted(nodeID) + require.False(ok) } diff --git a/snow/engine/snowman/transitive.go b/snow/engine/snowman/transitive.go index 1cdfce43df95..5daf34ba76fd 100644 --- a/snow/engine/snowman/transitive.go +++ b/snow/engine/snowman/transitive.go @@ -249,23 +249,8 @@ func (t *Transitive) PushQuery(ctx context.Context, nodeID ids.NodeID, requestID return t.buildBlocks(ctx) } -func (t *Transitive) Chits(ctx context.Context, nodeID ids.NodeID, requestID uint32, votes []ids.ID, accepted []ids.ID) error { - t.acceptedFrontiers.SetAcceptedFrontier(nodeID, accepted) - - // Since this is a linear chain, there should only be one ID in the vote set - if len(votes) != 1 { - t.Ctx.Log.Debug("failing Chits", - zap.String("reason", "expected only 1 vote"), - zap.Int("numVotes", len(votes)), - zap.Stringer("nodeID", nodeID), - zap.Uint32("requestID", requestID), - ) - // because QueryFailed doesn't utilize the assumption that we actually - // sent a Query message, we can safely call QueryFailed here to - // potentially abandon the request. - return t.QueryFailed(ctx, nodeID, requestID) - } - blkID := votes[0] +func (t *Transitive) Chits(ctx context.Context, nodeID ids.NodeID, requestID uint32, blkID ids.ID, acceptedID ids.ID) error { + t.acceptedFrontiers.SetLastAccepted(nodeID, acceptedID) t.Ctx.Log.Verbo("called Chits for the block", zap.Stringer("blkID", blkID), @@ -295,10 +280,8 @@ func (t *Transitive) Chits(ctx context.Context, nodeID ids.NodeID, requestID uin } func (t *Transitive) QueryFailed(ctx context.Context, nodeID ids.NodeID, requestID uint32) error { - lastAccepted := t.acceptedFrontiers.AcceptedFrontier(nodeID) - if len(lastAccepted) == 1 { - // Chits calls QueryFailed if [votes] doesn't have length 1, so this - // check is required to avoid infinite mutual recursion. + lastAccepted, ok := t.acceptedFrontiers.LastAccepted(nodeID) + if ok { return t.Chits(ctx, nodeID, requestID, lastAccepted, lastAccepted) } @@ -463,9 +446,9 @@ func (t *Transitive) GetBlock(ctx context.Context, blkID ids.ID) (snowman.Block, func (t *Transitive) sendChits(ctx context.Context, nodeID ids.NodeID, requestID uint32) { lastAccepted := t.Consensus.LastAccepted() if t.Ctx.StateSyncing.Get() { - t.Sender.SendChits(ctx, nodeID, requestID, []ids.ID{lastAccepted}, []ids.ID{lastAccepted}) + t.Sender.SendChits(ctx, nodeID, requestID, lastAccepted, lastAccepted) } else { - t.Sender.SendChits(ctx, nodeID, requestID, []ids.ID{t.Consensus.Preference()}, []ids.ID{lastAccepted}) + t.Sender.SendChits(ctx, nodeID, requestID, t.Consensus.Preference(), lastAccepted) } } diff --git a/snow/engine/snowman/transitive_test.go b/snow/engine/snowman/transitive_test.go index b00f8afcd49a..e43f0710145e 100644 --- a/snow/engine/snowman/transitive_test.go +++ b/snow/engine/snowman/transitive_test.go @@ -213,7 +213,7 @@ func TestEngineQuery(t *testing.T) { } chitted := new(bool) - sender.SendChitsF = func(_ context.Context, inVdr ids.NodeID, requestID uint32, prefSet []ids.ID, accepted []ids.ID) { + sender.SendChitsF = func(_ context.Context, inVdr ids.NodeID, requestID uint32, vote ids.ID, accepted ids.ID) { if *chitted { t.Fatalf("Sent multiple chits") } @@ -221,16 +221,10 @@ func TestEngineQuery(t *testing.T) { if requestID != 15 { t.Fatalf("Wrong request ID") } - if len(prefSet) != 1 { - t.Fatal("Should only be one vote") - } - if gBlk.ID() != prefSet[0] { + if gBlk.ID() != vote { t.Fatalf("Wrong chits block") } - if len(accepted) != 1 { - t.Fatal("accepted should only have one element") - } - if gBlk.ID() != accepted[0] { + if gBlk.ID() != accepted { t.Fatalf("Wrong accepted frontier") } } @@ -343,7 +337,7 @@ func TestEngineQuery(t *testing.T) { t.Fatalf("Asking for wrong block") } } - if err := te.Chits(context.Background(), vdr, *queryRequestID, []ids.ID{blk1.ID()}, nil); err != nil { + if err := te.Chits(context.Background(), vdr, *queryRequestID, blk1.ID(), blk1.ID()); err != nil { t.Fatal(err) } @@ -553,11 +547,10 @@ func TestEngineMultipleQuery(t *testing.T) { t.Fatalf("Asking for wrong block") } } - blkSet := []ids.ID{blk1.ID()} - if err := te.Chits(context.Background(), vdr0, *queryRequestID, blkSet, nil); err != nil { + if err := te.Chits(context.Background(), vdr0, *queryRequestID, blk1.ID(), blk1.ID()); err != nil { t.Fatal(err) } - if err := te.Chits(context.Background(), vdr1, *queryRequestID, blkSet, nil); err != nil { + if err := te.Chits(context.Background(), vdr1, *queryRequestID, blk1.ID(), blk1.ID()); err != nil { t.Fatal(err) } @@ -598,8 +591,7 @@ func TestEngineMultipleQuery(t *testing.T) { } // Should be dropped because the query was already filled - blkSet = []ids.ID{blk0.ID()} - if err := te.Chits(context.Background(), vdr2, *queryRequestID, blkSet, nil); err != nil { + if err := te.Chits(context.Background(), vdr2, *queryRequestID, blk0.ID(), blk0.ID()); err != nil { t.Fatal(err) } @@ -769,7 +761,7 @@ func TestEnginePushQuery(t *testing.T) { } chitted := new(bool) - sender.SendChitsF = func(_ context.Context, inVdr ids.NodeID, requestID uint32, votes []ids.ID, accepted []ids.ID) { + sender.SendChitsF = func(_ context.Context, inVdr ids.NodeID, requestID uint32, vote ids.ID, accepted ids.ID) { if *chitted { t.Fatalf("Sent chit multiple times") } @@ -780,16 +772,10 @@ func TestEnginePushQuery(t *testing.T) { if requestID != 20 { t.Fatalf("Wrong request id") } - if len(votes) != 1 { - t.Fatal("votes should only have one element") - } - if gBlk.ID() != votes[0] { + if gBlk.ID() != vote { t.Fatalf("Asking for wrong block") } - if len(accepted) != 1 { - t.Fatal("accepted should only have one element") - } - if gBlk.ID() != accepted[0] { + if gBlk.ID() != accepted { t.Fatalf("Wrong accepted frontier") } } @@ -1205,7 +1191,7 @@ func TestEngineAbandonChit(t *testing.T) { } // Register a voter dependency on an unknown block. - require.NoError(te.Chits(context.Background(), vdr, reqID, []ids.ID{fakeBlkID}, nil)) + require.NoError(te.Chits(context.Background(), vdr, reqID, fakeBlkID, fakeBlkID)) require.Len(te.blocked, 1) sender.CantSendPullQuery = false @@ -1260,7 +1246,7 @@ func TestEngineAbandonChitWithUnexpectedPutBlock(t *testing.T) { } // Register a voter dependency on an unknown block. - require.NoError(te.Chits(context.Background(), vdr, reqID, []ids.ID{fakeBlkID}, nil)) + require.NoError(te.Chits(context.Background(), vdr, reqID, fakeBlkID, fakeBlkID)) require.Len(te.blocked, 1) sender.CantSendPullQuery = false @@ -1427,7 +1413,7 @@ func TestEngineBlockingChitResponse(t *testing.T) { sender.SendPushQueryF = nil sender.CantSendPushQuery = false - if err := te.Chits(context.Background(), vdr, *queryRequestID, []ids.ID{blockingBlk.ID()}, nil); err != nil { + if err := te.Chits(context.Background(), vdr, *queryRequestID, blockingBlk.ID(), blockingBlk.ID()); err != nil { t.Fatal(err) } @@ -1545,7 +1531,7 @@ func TestEngineUndeclaredDependencyDeadlock(t *testing.T) { t.Fatal(err) } - if err := te.Chits(context.Background(), vdr, *reqID, []ids.ID{invalidBlkID}, nil); err != nil { + if err := te.Chits(context.Background(), vdr, *reqID, invalidBlkID, invalidBlkID); err != nil { t.Fatal(err) } @@ -2003,13 +1989,11 @@ func TestEngineDoubleChit(t *testing.T) { panic("Should have errored") } - blkSet := []ids.ID{blk.ID()} - if status := blk.Status(); status != choices.Processing { t.Fatalf("Wrong status: %s ; expected: %s", status, choices.Processing) } - if err := te.Chits(context.Background(), vdr0, *queryRequestID, blkSet, nil); err != nil { + if err := te.Chits(context.Background(), vdr0, *queryRequestID, blk.ID(), blk.ID()); err != nil { t.Fatal(err) } @@ -2017,7 +2001,7 @@ func TestEngineDoubleChit(t *testing.T) { t.Fatalf("Wrong status: %s ; expected: %s", status, choices.Processing) } - if err := te.Chits(context.Background(), vdr0, *queryRequestID, blkSet, nil); err != nil { + if err := te.Chits(context.Background(), vdr0, *queryRequestID, blk.ID(), blk.ID()); err != nil { t.Fatal(err) } @@ -2025,7 +2009,7 @@ func TestEngineDoubleChit(t *testing.T) { t.Fatalf("Wrong status: %s ; expected: %s", status, choices.Processing) } - if err := te.Chits(context.Background(), vdr1, *queryRequestID, blkSet, nil); err != nil { + if err := te.Chits(context.Background(), vdr1, *queryRequestID, blk.ID(), blk.ID()); err != nil { t.Fatal(err) } @@ -2170,7 +2154,7 @@ func TestEngineBuildBlockLimit(t *testing.T) { } } - if err := te.Chits(context.Background(), vdr, reqID, []ids.ID{blk0.ID()}, nil); err != nil { + if err := te.Chits(context.Background(), vdr, reqID, blk0.ID(), blk0.ID()); err != nil { t.Fatal(err) } @@ -2252,7 +2236,7 @@ func TestEngineReceiveNewRejectedBlock(t *testing.T) { t.Fatalf("Didn't query for the new block") } - if err := te.Chits(context.Background(), vdr, reqID, []ids.ID{acceptedBlk.ID()}, nil); err != nil { + if err := te.Chits(context.Background(), vdr, reqID, acceptedBlk.ID(), acceptedBlk.ID()); err != nil { t.Fatal(err) } @@ -2367,7 +2351,7 @@ func TestEngineRejectionAmplification(t *testing.T) { } } - if err := te.Chits(context.Background(), vdr, reqID, []ids.ID{acceptedBlk.ID()}, nil); err != nil { + if err := te.Chits(context.Background(), vdr, reqID, acceptedBlk.ID(), acceptedBlk.ID()); err != nil { t.Fatal(err) } @@ -2488,7 +2472,7 @@ func TestEngineTransitiveRejectionAmplificationDueToRejectedParent(t *testing.T) t.Fatalf("Didn't query for the new block") } - if err := te.Chits(context.Background(), vdr, reqID, []ids.ID{acceptedBlk.ID()}, nil); err != nil { + if err := te.Chits(context.Background(), vdr, reqID, acceptedBlk.ID(), acceptedBlk.ID()); err != nil { t.Fatal(err) } @@ -2597,7 +2581,7 @@ func TestEngineTransitiveRejectionAmplificationDueToInvalidParent(t *testing.T) } } - if err := te.Chits(context.Background(), vdr, reqID, []ids.ID{acceptedBlk.ID()}, nil); err != nil { + if err := te.Chits(context.Background(), vdr, reqID, acceptedBlk.ID(), acceptedBlk.ID()); err != nil { t.Fatal(err) } @@ -2810,7 +2794,7 @@ func TestEngineBubbleVotesThroughInvalidBlock(t *testing.T) { // Now we are expecting a Chits message, and we receive it for [blk2] // instead of [blk1]. This will cause the node to again request [blk2]. - require.NoError(te.Chits(context.Background(), vdr, *queryRequestID, []ids.ID{blk2.ID()}, nil)) + require.NoError(te.Chits(context.Background(), vdr, *queryRequestID, blk2.ID(), blk2.ID())) // The votes should be bubbled through [blk2] despite the fact that it is // failing verification. @@ -2848,7 +2832,7 @@ func TestEngineBubbleVotesThroughInvalidBlock(t *testing.T) { require.True(*queried) // After a single vote for [blk2], it should be marked as accepted. - require.NoError(te.Chits(context.Background(), vdr, *queryRequestID, []ids.ID{blk2.ID()}, nil)) + require.NoError(te.Chits(context.Background(), vdr, *queryRequestID, blk2.ID(), blk2.ID())) require.Equal(choices.Accepted, blk2.Status()) } @@ -2989,7 +2973,7 @@ func TestEngineBubbleVotesThroughInvalidChain(t *testing.T) { // Now we are expecting a Chits message and we receive it for [blk3]. // This will cause the node to again request [blk3]. - require.NoError(te.Chits(context.Background(), vdr, *queryRequestID, []ids.ID{blk3.ID()}, nil)) + require.NoError(te.Chits(context.Background(), vdr, *queryRequestID, blk3.ID(), blk3.ID())) // Drop the re-request for [blk3] to cause the poll to terminate. The votes // should be bubbled through [blk3] despite the fact that it hasn't been @@ -3119,8 +3103,8 @@ func TestEngineBuildBlockWithCachedNonVerifiedParent(t *testing.T) { require.NoError(te.Put(context.Background(), vdr, 0, parentBlkA.BytesV)) // Give 2 chits for [parentBlkA]/[parentBlkB] - require.NoError(te.Chits(context.Background(), vdr, *queryRequestAID, []ids.ID{parentBlkB.IDV}, nil)) - require.NoError(te.Chits(context.Background(), vdr, *queryRequestGPID, []ids.ID{parentBlkB.IDV}, nil)) + require.NoError(te.Chits(context.Background(), vdr, *queryRequestAID, parentBlkB.IDV, parentBlkB.IDV)) + require.NoError(te.Chits(context.Background(), vdr, *queryRequestGPID, parentBlkB.IDV, parentBlkB.IDV)) // Assert that the blocks' statuses are correct. // The evicted [parentBlkA] shouldn't be changed. @@ -3232,8 +3216,7 @@ func TestEngineApplyAcceptedFrontierInQueryFailed(t *testing.T) { *queryRequestID = requestID } - blkIDs := []ids.ID{blk.ID()} - require.NoError(te.Chits(context.Background(), vdr, *queryRequestID, blkIDs, blkIDs)) + require.NoError(te.Chits(context.Background(), vdr, *queryRequestID, blk.ID(), blk.ID())) require.Equal(choices.Processing, blk.Status()) diff --git a/snow/networking/handler/handler.go b/snow/networking/handler/handler.go index 3a600a1799c6..41d6e6cdc454 100644 --- a/snow/networking/handler/handler.go +++ b/snow/networking/handler/handler.go @@ -712,31 +712,31 @@ func (h *handler) handleSyncMsg(ctx context.Context, msg Message) error { return engine.PullQuery(ctx, nodeID, msg.RequestId, containerID) case *p2p.Chits: - votes, err := getIDs(msg.PreferredContainerIds) + preferredID, err := ids.ToID(msg.PreferredId) if err != nil { h.ctx.Log.Debug("message with invalid field", zap.Stringer("nodeID", nodeID), zap.Stringer("messageOp", message.ChitsOp), zap.Uint32("requestID", msg.RequestId), - zap.String("field", "PreferredContainerIDs"), + zap.String("field", "PreferredID"), zap.Error(err), ) return engine.QueryFailed(ctx, nodeID, msg.RequestId) } - accepted, err := getIDs(msg.AcceptedContainerIds) + acceptedID, err := ids.ToID(msg.AcceptedId) if err != nil { h.ctx.Log.Debug("message with invalid field", zap.Stringer("nodeID", nodeID), zap.Stringer("messageOp", message.ChitsOp), zap.Uint32("requestID", msg.RequestId), - zap.String("field", "AcceptedContainerIDs"), + zap.String("field", "AcceptedID"), zap.Error(err), ) return engine.QueryFailed(ctx, nodeID, msg.RequestId) } - return engine.Chits(ctx, nodeID, msg.RequestId, votes, accepted) + return engine.Chits(ctx, nodeID, msg.RequestId, preferredID, acceptedID) case *message.QueryFailed: return engine.QueryFailed(ctx, nodeID, msg.RequestID) diff --git a/snow/networking/handler/handler_test.go b/snow/networking/handler/handler_test.go index ccc694ae1991..9800a643ec5d 100644 --- a/snow/networking/handler/handler_test.go +++ b/snow/networking/handler/handler_test.go @@ -584,7 +584,7 @@ func TestDynamicEngineTypeDispatch(t *testing.T) { engine.ContextF = func() *snow.ConsensusContext { return ctx } - engine.ChitsF = func(ctx context.Context, nodeID ids.NodeID, requestID uint32, preferredIDs []ids.ID, acceptedIDs []ids.ID) error { + engine.ChitsF = func(context.Context, ids.NodeID, uint32, ids.ID, ids.ID) error { close(messageReceived) return nil } @@ -605,8 +605,8 @@ func TestDynamicEngineTypeDispatch(t *testing.T) { InboundMessage: message.InboundChits( ids.Empty, uint32(0), - nil, - nil, + ids.Empty, + ids.Empty, ids.EmptyNodeID, ), EngineType: test.requestedEngineType, diff --git a/snow/networking/router/chain_router_test.go b/snow/networking/router/chain_router_test.go index 2027f2ddb2b7..6d886c078e9d 100644 --- a/snow/networking/router/chain_router_test.go +++ b/snow/networking/router/chain_router_test.go @@ -1022,8 +1022,8 @@ func TestRouterClearTimeouts(t *testing.T) { msg := message.InboundChits( ctx.ChainID, requestID, - nil, - nil, + ids.Empty, + ids.Empty, nodeID, ) chainRouter.HandleInbound(context.Background(), msg) diff --git a/snow/networking/sender/sender.go b/snow/networking/sender/sender.go index afacef3a5d51..b8d9bee74f41 100644 --- a/snow/networking/sender/sender.go +++ b/snow/networking/sender/sender.go @@ -1153,7 +1153,7 @@ func (s *sender) SendPullQuery(ctx context.Context, nodeIDs set.Set[ids.NodeID], } // SendChits sends chits -func (s *sender) SendChits(ctx context.Context, nodeID ids.NodeID, requestID uint32, votes, accepted []ids.ID) { +func (s *sender) SendChits(ctx context.Context, nodeID ids.NodeID, requestID uint32, preferredID, acceptedID ids.ID) { ctx = utils.Detach(ctx) // If [nodeID] is myself, send this message directly @@ -1162,8 +1162,8 @@ func (s *sender) SendChits(ctx context.Context, nodeID ids.NodeID, requestID uin inMsg := message.InboundChits( s.ctx.ChainID, requestID, - votes, - accepted, + preferredID, + acceptedID, nodeID, ) go s.router.HandleInbound(ctx, inMsg) @@ -1171,13 +1171,14 @@ func (s *sender) SendChits(ctx context.Context, nodeID ids.NodeID, requestID uin } // Create the outbound message. - outMsg, err := s.msgCreator.Chits(s.ctx.ChainID, requestID, votes, accepted) + outMsg, err := s.msgCreator.Chits(s.ctx.ChainID, requestID, preferredID, acceptedID) if err != nil { s.ctx.Log.Error("failed to build message", zap.Stringer("messageOp", message.ChitsOp), zap.Stringer("chainID", s.ctx.ChainID), zap.Uint32("requestID", requestID), - zap.Stringers("containerIDs", votes), + zap.Stringer("preferredID", preferredID), + zap.Stringer("acceptedID", acceptedID), zap.Error(err), ) return @@ -1198,7 +1199,8 @@ func (s *sender) SendChits(ctx context.Context, nodeID ids.NodeID, requestID uin zap.Stringer("nodeID", nodeID), zap.Stringer("chainID", s.ctx.ChainID), zap.Uint32("requestID", requestID), - zap.Stringers("containerIDs", votes), + zap.Stringer("preferredID", preferredID), + zap.Stringer("acceptedID", acceptedID), ) } } diff --git a/snow/networking/sender/traced_sender.go b/snow/networking/sender/traced_sender.go index a6ffe7f4ab21..a60118af470f 100644 --- a/snow/networking/sender/traced_sender.go +++ b/snow/networking/sender/traced_sender.go @@ -177,16 +177,16 @@ func (s *tracedSender) SendPullQuery(ctx context.Context, nodeIDs set.Set[ids.No s.sender.SendPullQuery(ctx, nodeIDs, requestID, containerID) } -func (s *tracedSender) SendChits(ctx context.Context, nodeID ids.NodeID, requestID uint32, votes []ids.ID, accepted []ids.ID) { +func (s *tracedSender) SendChits(ctx context.Context, nodeID ids.NodeID, requestID uint32, preferredID ids.ID, acceptedID ids.ID) { ctx, span := s.tracer.Start(ctx, "tracedSender.SendChits", oteltrace.WithAttributes( attribute.Stringer("recipients", nodeID), attribute.Int64("requestID", int64(requestID)), - attribute.Int("numVotes", len(votes)), - attribute.Int("numAccepted", len(accepted)), + attribute.Stringer("preferredID", preferredID), + attribute.Stringer("acceptedID", acceptedID), )) defer span.End() - s.sender.SendChits(ctx, nodeID, requestID, votes, accepted) + s.sender.SendChits(ctx, nodeID, requestID, preferredID, acceptedID) } func (s *tracedSender) SendCrossChainAppRequest(ctx context.Context, chainID ids.ID, requestID uint32, appRequestBytes []byte) error {