Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added listeners to TX and new blocks cerated in the system #444

Merged
merged 5 commits into from Jan 16, 2019

Conversation

antonlerner
Copy link
Contributor

No description provided.

@zalmen zalmen self-assigned this Jan 15, 2019
Data: data,
Coin: coin,
}
return &b
}

func NewSerializableTransaction(nonce uint64, origin, recepient common.Address, amount, price *big.Int, gasLimit uint64) *SerializableTransaction{
Copy link
Contributor

Choose a reason for hiding this comment

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

amount isn't used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch

mesh/block.go Outdated
return w.Bytes(), nil
}

func BytesAsTransaction(buf io.Reader) (SerializableTransaction, error){
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider returning a pointer to SerializableTx

@@ -19,10 +21,13 @@ const MaxTransactionsPerBlock = 200 //todo: move to config
const DefaultGasLimit =10
const DefaultGas = 1

const TxGossipChannel = "TxGossip"
Copy link
Contributor

Choose a reason for hiding this comment

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

We need a agree on a unified format for the protocol names (perhaps something that contain a version also), add a todo so once we decide on a format we'll change this

@@ -81,6 +90,7 @@ func (t *BlockBuilder) Stop() error{
if !t.started {
return fmt.Errorf("already stopped")
}
t.started = false
t.stopChan <- struct{}{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Both acceptBlockData and listenForTx listen on the stopChan channel. That means that only one of them will get the stop message and the other one will continue running. When you want them to stop, instead of sending a message on the channel you should kill the channel

Copy link
Contributor Author

Choose a reason for hiding this comment

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

stopchannel needs to be closed, this way the event is received on all listeners

case data := <- t.txGossipChannel:
x, err := mesh.BytesAsTransaction(bytes.NewReader(data.Bytes()))
if err != nil {
log.Error("cannot parse incoming TX")
Copy link
Contributor

Choose a reason for hiding this comment

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

missing continue? currently you're sending the byte array although the serialisation failed

}
}
}


func (t *BlockBuilder) acceptBlockData() {
for {
Copy link
Contributor

Choose a reason for hiding this comment

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

under the case <-t.stopChan: - you shouldn't set t.started to false, the Stop method already take care of it

case data := <- bl.receivedGossipBlocks:
blk, err := mesh.BytesAsBlock(bytes.NewReader(data.Bytes()))
if err != nil {
log.Error("received invalid block from sender %v", data.Sender())
Copy link
Contributor

Choose a reason for hiding this comment

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

break on failure?

@antonlerner antonlerner merged commit ef58682 into develop Jan 16, 2019
@y0sher y0sher deleted the mining_blocks branch June 25, 2019 07: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.

None yet

2 participants