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
Conversation
Data: data, | ||
Coin: coin, | ||
} | ||
return &b | ||
} | ||
|
||
func NewSerializableTransaction(nonce uint64, origin, recepient common.Address, amount, price *big.Int, gasLimit uint64) *SerializableTransaction{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
amount
isn't used
There was a problem hiding this comment.
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){ |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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{}{} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
break on failure?
No description provided.