Skip to content

Commit

Permalink
Handle empty IO replication tree
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel committed Mar 17, 2022
1 parent 4fd44a8 commit fd8ef3e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 10 additions & 1 deletion lib/archethic/mining/validation_context.ex
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,9 @@ defmodule ArchEthic.Mining.ValidationContext do
sub_chain_tree = Enum.at(chain_tree, validator_index)

sub_beacon_tree = Enum.at(beacon_tree, validator_index)
sub_io_tree = Enum.at(io_tree, validator_index)

# IO tree can be empty, if there are not recipients
sub_io_tree = Enum.at(io_tree, validator_index, [])

%{
context
Expand Down Expand Up @@ -1072,6 +1074,13 @@ defmodule ArchEthic.Mining.ValidationContext do
Get the list of I/O replication nodes
"""
@spec get_io_replication_nodes(t()) :: list(Node.t())
def get_io_replication_nodes(%__MODULE__{
sub_replication_tree: %{
IO: []
}
}),
do: []

def get_io_replication_nodes(%__MODULE__{
sub_replication_tree: %{
IO: sub_tree
Expand Down
8 changes: 6 additions & 2 deletions lib/archethic/p2p/message.ex
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ defmodule ArchEthic.P2P.Message do
tree_size::8, :erlang.list_to_bitstring(chain_replication_tree)::bitstring,
:erlang.list_to_bitstring(beacon_replication_tree)::bitstring,
:erlang.list_to_bitstring(io_replication_tree)::bitstring,
length(io_replication_tree)::8, :erlang.list_to_bitstring(io_replication_tree)::bitstring,
bit_size(confirmed_validation_nodes)::8, confirmed_validation_nodes::bitstring>>
end

Expand Down Expand Up @@ -567,8 +568,11 @@ defmodule ArchEthic.P2P.Message do
<<nb_validations::8, tree_size::8, rest::bitstring>> = rest

{chain_tree, rest} = deserialize_bit_sequences(rest, nb_validations, tree_size, [])
{beacon_tree, rest} = deserialize_bit_sequences(rest, nb_validations, tree_size, [])
{io_tree, rest} = deserialize_bit_sequences(rest, nb_validations, tree_size, [])

{beacon_tree, <<io_tree_size::8, rest::bitstring>>} =
deserialize_bit_sequences(rest, nb_validations, tree_size, [])

{io_tree, rest} = deserialize_bit_sequences(rest, io_tree_size, tree_size, [])

<<nb_cross_validation_nodes::8,
cross_validation_node_confirmation::bitstring-size(nb_cross_validation_nodes),
Expand Down

0 comments on commit fd8ef3e

Please sign in to comment.