Skip to content

Conversation

@meivantodorov
Copy link
Contributor

@meivantodorov meivantodorov commented Oct 30, 2017

General description

  • Validated blocks are sent to other peers via http request asynchronously
  • Received blocks are validated and added to the chain if validation is successful
  • Improved the flow for sending asyc request.

closes #75

end)

## Block was validated, now we can send it to other peers
serialized_block = Serialization.block(b, :serialize)
Copy link
Collaborator

Choose a reason for hiding this comment

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

the serialization should not bein the chain

end

## Internal functions
defp send_to_peers(:post, uri, data, []) do
Copy link
Collaborator

@thepiwo thepiwo Oct 31, 2017

Choose a reason for hiding this comment

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

there sould be no special case, for peer <- peers do should work with empty list. You can log to debug after sending to how many peers it was sent

true -> Logger.info(" This transaction has already been added")
false -> Peers.broadcast_tx(tx)
true -> Logger.info(" This transaction already has been added")
false -> Peers.async_request({:new_tx, Serialization.tx(tx, :serialize)})
Copy link
Collaborator

Choose a reason for hiding this comment

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

do the serialization by case in async_request

@doc """
Every async requests to the peers will be send from here
"""
@spec async_request({type :: atom(), data :: term()}) :: :ok | :error
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should have a more semantic correct name, like broadcast_all_peers

defp send_to_peers(:post, uri, data, []) do
Logger.warn("Empty peers list")
end
defp send_to_peers(:post, uri, data, peers) do
Copy link
Collaborator

Choose a reason for hiding this comment

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

sending will always happen with :post, no need to specify. What is uri needed for, each peer should have its own uri

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

I have to look at it in more detail, thanks

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you rename it to something else? In the peers worker, uri is always used as the address of the peer, this is why I was so confused

@thepiwo
Copy link
Collaborator

thepiwo commented Nov 1, 2017

can you resolve the compiler warnings, as well?

@thepiwo
Copy link
Collaborator

thepiwo commented Nov 1, 2017

When having two nodes, mining on the first one, suspending and then continue mining on the second node [error] Failed to add block: Incorrect previous hash occures, but the blocks are still added to the chain and broadcasted.

@andonov andonov merged commit bc4dbc7 into master Nov 1, 2017
@thepiwo thepiwo deleted the GH-75 branch October 5, 2018 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

broadcast new block to all peers

5 participants