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 listener for ATXs #738
Conversation
879587e
to
163129b
Compare
activation/activation.go
Outdated
return err | ||
} | ||
//todo: should we do something about it? wait for something? | ||
b.net.Broadcast(miner.IncomingAtxProtocol, buf) |
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.
broadcast returns error you can do
return b.net.Broadcast(miner.IncomingAtxProtocol, buf)
mesh/mesh.go
Outdated
@@ -30,6 +30,10 @@ type StateUpdater interface { | |||
ApplyRewards(layer LayerID, miners map[string]struct{}, underQuota map[string]struct{}, bonusReward, diminishedReward *big.Int) | |||
} | |||
|
|||
type AtxDb interface { |
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 don't use this interface, if its not for future implementation
we can delete this
mesh/activation.go
Outdated
//todo: choose which type is VRF | ||
type Vrf string | ||
|
||
type Id 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.
i think we should give this a more descriptive name.
mesh.Id can pretty much mean anything in our context
if err != nil { | ||
return err | ||
} | ||
|
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.
addAtxToLayer and db.addAtxToNodeId can fail
we should handle those errors so we wont endup with atx's that are not fully saved
activation/db.go
Outdated
if err != nil { | ||
return errors.New("could not encode layer block ids") | ||
} | ||
db.Atxs.Put(l.ToBytes(), w) |
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.
handle error returned from put
activation/db.go
Outdated
return errors.New("could not encode layer block ids") | ||
} | ||
db.Atxs.Put(nodeId.ToBytes(), w) | ||
return nil |
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.
handle error returned from put
mesh/activation.go
Outdated
} | ||
|
||
func BytesAsAtx(buf io.Reader) (*ActivationTx, error) { | ||
b := ActivationTx{} |
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.
you can do the Reader conversion inside the method insted of always doing it when you call BytesAsAtx
activation/activation.go
Outdated
return nil | ||
} | ||
|
||
func (b *Builder) GetPrevAtx(node mesh.Id) (*mesh.AtxId, 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.
Should change to GetPrevAtxId
. It's confusing otherwise.
activation/activation.go
Outdated
Sequence: b.GetLastSequence(b.nodeId) + 1, | ||
PrevATX: *prevAtx, | ||
LayerIndex: l, | ||
StartTick: 0, //todo: whatever |
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.
What about EndTick
? you want it to be computed (startTick + NIPST difficulty)? If so, perhaps include the computing method.
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.
Still open.
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.
I've included the end tick however these are just place holders, see comments in struct addressing this
activation/activation.go
Outdated
if err != nil { | ||
return err | ||
} | ||
atx := mesh.ActivationTx{ |
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.
Why not using mesh.NewActivationTx
? If not useful, perhaps remove it entirely.
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.
Still open.
miner/block_builder.go
Outdated
data.ReportValidation(IncomingTxProtocol, false) | ||
break | ||
} | ||
data.ReportValidation(IncomingTxProtocol, true) |
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.
Update the protocol string (IncomingTxProtocol
-> IncomingAtxProtocol
).
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.
Still open.
miner/block_builder.go
Outdated
data.ReportValidation(IncomingTxProtocol, false) | ||
break | ||
} | ||
data.ReportValidation(IncomingTxProtocol, true) |
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.
Where the ATX syntactic validity checks will happen?
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.
TBD, will add a comment
activation/activation.go
Outdated
if err != nil { | ||
return err | ||
} | ||
atx := mesh.ActivationTx{ |
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.
Still open.
activation/activation.go
Outdated
Sequence: b.GetLastSequence(b.nodeId) + 1, | ||
PrevATX: *prevAtx, | ||
LayerIndex: l, | ||
StartTick: 0, //todo: whatever |
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.
Still open.
activation/activation.go
Outdated
StartTick: 0, //todo: whatever | ||
PositioningATX: *posAtx, | ||
ActiveSetSize: b.activeSet.GetActiveSetSize(l - 1), | ||
View: b.mesh.GetLatestView(), |
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.
Still open.
|
||
func (db *ActivationDb) StoreAtx(atx mesh.ActivationTx) error { | ||
if b, err := db.Atxs.Get(atx.Id().Bytes()); err == nil && len(b) > 0 { | ||
// exists - how should we handle this? |
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.
Still open.
activation/db.go
Outdated
} else { | ||
atxs, err = decodeAtxIds(ids) | ||
if err != nil { | ||
return errors.New("could not get all blocks from database ") |
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.
Still open.
@@ -91,6 +94,8 @@ func newBlockHeader(block *Block) *BlockHeader { | |||
Coin: block.Coin, | |||
MinerID: block.MinerID, | |||
TxIds: tids, | |||
//todo: set only ATX ids here and dedup | |||
ATXs: block.ATXs, |
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.
Still open.
miner/block_builder.go
Outdated
data.ReportValidation(IncomingTxProtocol, false) | ||
break | ||
} | ||
data.ReportValidation(IncomingTxProtocol, true) |
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.
Still open.
|
||
const DefaultGasLimit = 10 | ||
const DefaultGas = 1 | ||
|
||
const IncomingTxProtocol = "TxGossip" | ||
const AtxProtocol = "AtxGossip" |
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.
Please IncomingTxProtocol
as well.
} | ||
|
||
func (b Builder) BuildActivationTx(nipst *nipst.NIPST) error { | ||
prevAtx, err := b.GetPrevAtxId(b.nodeId) |
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.
Update the variable name as well (prevAtx
-> prevAtxId
).
return &atxId, nil | ||
} | ||
|
||
func (b *Builder) GetLastSequence(node mesh.NodeId) uint64 { |
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.
Why having all the errors here silent?
(Still open)
440d8c5
to
8dd725c
Compare
Added basic implementation of ATX and the addition of the ATXs to a mined block