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 listener for ATXs #738

Merged
merged 6 commits into from Apr 1, 2019
Merged

added listener for ATXs #738

merged 6 commits into from Apr 1, 2019

Conversation

antonlerner
Copy link
Contributor

Added basic implementation of ATX and the addition of the ATXs to a mined block

return err
}
//todo: should we do something about it? wait for something?
b.net.Broadcast(miner.IncomingAtxProtocol, buf)
Copy link
Contributor

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 {
Copy link
Contributor

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

//todo: choose which type is VRF
type Vrf string

type Id struct {
Copy link
Contributor

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
}

Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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

}

func BytesAsAtx(buf io.Reader) (*ActivationTx, error) {
b := ActivationTx{}
Copy link
Contributor

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

return nil
}

func (b *Builder) GetPrevAtx(node mesh.Id) (*mesh.AtxId, error) {
Copy link
Contributor

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 Show resolved Hide resolved
activation/activation.go Outdated Show resolved Hide resolved
Sequence: b.GetLastSequence(b.nodeId) + 1,
PrevATX: *prevAtx,
LayerIndex: l,
StartTick: 0, //todo: whatever
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Still open.

Copy link
Contributor Author

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

if err != nil {
return err
}
atx := mesh.ActivationTx{
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Still open.

mesh/block.go Outdated Show resolved Hide resolved
data.ReportValidation(IncomingTxProtocol, false)
break
}
data.ReportValidation(IncomingTxProtocol, true)
Copy link
Contributor

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).

Copy link
Contributor

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 Show resolved Hide resolved
miner/block_builder.go Outdated Show resolved Hide resolved
data.ReportValidation(IncomingTxProtocol, false)
break
}
data.ReportValidation(IncomingTxProtocol, true)
Copy link
Contributor

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?

Copy link
Contributor Author

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

if err != nil {
return err
}
atx := mesh.ActivationTx{
Copy link
Contributor

Choose a reason for hiding this comment

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

Still open.

Sequence: b.GetLastSequence(b.nodeId) + 1,
PrevATX: *prevAtx,
LayerIndex: l,
StartTick: 0, //todo: whatever
Copy link
Contributor

Choose a reason for hiding this comment

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

Still open.

StartTick: 0, //todo: whatever
PositioningATX: *posAtx,
ActiveSetSize: b.activeSet.GetActiveSetSize(l - 1),
View: b.mesh.GetLatestView(),
Copy link
Contributor

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?
Copy link
Contributor

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 ")
Copy link
Contributor

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,
Copy link
Contributor

Choose a reason for hiding this comment

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

Still open.

data.ReportValidation(IncomingTxProtocol, false)
break
}
data.ReportValidation(IncomingTxProtocol, true)
Copy link
Contributor

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"
Copy link
Contributor

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)
Copy link
Contributor

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 {
Copy link
Contributor

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)

@antonlerner antonlerner merged commit 4daf5e1 into develop Apr 1, 2019
@antonlerner antonlerner deleted the activation_tx branch April 1, 2019 18:08
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

3 participants