Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions protocol/chainsync/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@ func TestGetAvailableBlockRange(t *testing.T) {
testBlock.SlotNumber(),
testBlock.Hash().Bytes(),
)

rollForwardMsg, err := chainsync.NewMsgRollForwardNtC(
ledger.BlockTypeBabbage,
blockCbor,
expectedTip,
)
if err != nil {
t.Fatalf("failed to create RollForward message: %s", err)
}

conversation := append(
conversationHandshakeFindIntersect,
ouroboros_mock.ConversationEntryOutput{
Expand Down Expand Up @@ -235,11 +245,7 @@ func TestGetAvailableBlockRange(t *testing.T) {
ProtocolId: chainsync.ProtocolIdNtC,
IsResponse: true,
Messages: []protocol.Message{
chainsync.NewMsgRollForwardNtC(
ledger.BlockTypeBabbage,
blockCbor,
expectedTip,
),
rollForwardMsg,
},
},
)
Expand Down
7 changes: 3 additions & 4 deletions protocol/chainsync/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func NewMsgRollForwardNtC(
blockType uint,
blockCbor []byte,
tip Tip,
) *MsgRollForwardNtC {
) (*MsgRollForwardNtC, error) {
m := &MsgRollForwardNtC{
MessageBase: protocol.MessageBase{
MessageType: MessageTypeRollForward,
Expand All @@ -135,12 +135,11 @@ func NewMsgRollForwardNtC(
copy(m.blockCbor, blockCbor)
wb := NewWrappedBlock(blockType, blockCbor)
content, err := cbor.Encode(wb)
// TODO: figure out better way to handle error (#855)
if err != nil {
return nil
return nil, fmt.Errorf("failed to encode wrapped block: %w", err)
}
m.WrappedBlock = cbor.Tag{Number: 24, Content: content}
return m
return m, nil
}

func (m *MsgRollForwardNtC) UnmarshalCBOR(data []byte) error {
Expand Down
42 changes: 18 additions & 24 deletions protocol/chainsync/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,15 @@ func TestMsgRollForwardNodeToNode_CorruptedCBOR(t *testing.T) {
}
}
func TestMsgRollForwardNodeToClient(t *testing.T) {
createMsg := func(t *testing.T, blockType uint, filePath string, tip Tip) *MsgRollForwardNtC {
blockData := hexDecode(string(readFile(filePath)))
msg, err := NewMsgRollForwardNtC(blockType, blockData, tip)
if err != nil {
t.Fatalf("failed to create NewMsgRollForwardNtC: %v", err)
}
return msg
}

tests := []testDefinition{
// Byron EBB (NtC)
{
Expand All @@ -220,15 +229,10 @@ func TestMsgRollForwardNodeToClient(t *testing.T) {
"testdata/rollforward_ntc_byron_ebb_testnet_8f8602837f7c6f8b8867dd1cbc1842cf51a27eaed2c70ef48325d00f8efb320f.hex",
),
),
Message: NewMsgRollForwardNtC(
Message: createMsg(
t,
0,
hexDecode(
string(
readFile(
"testdata/byron_ebb_testnet_8f8602837f7c6f8b8867dd1cbc1842cf51a27eaed2c70ef48325d00f8efb320f.hex",
),
),
),
"testdata/byron_ebb_testnet_8f8602837f7c6f8b8867dd1cbc1842cf51a27eaed2c70ef48325d00f8efb320f.hex",
Tip{
Point: common.Point{
Slot: 49055,
Expand All @@ -249,15 +253,10 @@ func TestMsgRollForwardNodeToClient(t *testing.T) {
"testdata/rollforward_ntc_byron_main_block_testnet_f38aa5e8cf0b47d1ffa8b2385aa2d43882282db2ffd5ac0e3dadec1a6f2ecf08.hex",
),
),
Message: NewMsgRollForwardNtC(
Message: createMsg(
t,
1,
hexDecode(
string(
readFile(
"testdata/byron_main_block_testnet_f38aa5e8cf0b47d1ffa8b2385aa2d43882282db2ffd5ac0e3dadec1a6f2ecf08.hex",
),
),
),
"testdata/byron_main_block_testnet_f38aa5e8cf0b47d1ffa8b2385aa2d43882282db2ffd5ac0e3dadec1a6f2ecf08.hex",
Tip{
Point: common.Point{
Slot: 49055,
Expand All @@ -278,15 +277,10 @@ func TestMsgRollForwardNodeToClient(t *testing.T) {
"testdata/rollforward_ntc_shelley_block_testnet_02b1c561715da9e540411123a6135ee319b02f60b9a11a603d3305556c04329f.hex",
),
),
Message: NewMsgRollForwardNtC(
Message: createMsg(
t,
2,
hexDecode(
string(
readFile(
"testdata/shelley_block_testnet_02b1c561715da9e540411123a6135ee319b02f60b9a11a603d3305556c04329f.hex",
),
),
),
"testdata/shelley_block_testnet_02b1c561715da9e540411123a6135ee319b02f60b9a11a603d3305556c04329f.hex",
Tip{
Point: common.Point{
Slot: 55829927,
Expand Down
8 changes: 4 additions & 4 deletions protocol/chainsync/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,21 @@ func (s *Server) RollForward(blockType uint, blockData []byte, tip Tip) error {
}
return s.SendMessage(msg)
} else {
msg := NewMsgRollForwardNtC(
msg, err := NewMsgRollForwardNtC(
blockType,
blockData,
tip,
)
if msg == nil {
if err != nil {
s.Protocol.Logger().
Error(
"failed to create roll forward message",
fmt.Sprintf("failed to create roll forward message: %s", err),
"component", "network",
"protocol", ProtocolName,
"role", "server",
"connection_id", s.callbackContext.ConnectionId.String(),
)
return errors.New("failed to create roll forward message")
return fmt.Errorf("failed to create roll forward message: %w", err)
}
return s.SendMessage(msg)
}
Expand Down