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

Conversation

Projects
None yet
3 participants
@antonlerner
Copy link
Member

antonlerner commented Mar 27, 2019

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

@antonlerner antonlerner force-pushed the activation_tx branch from 879587e to 163129b Mar 27, 2019

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

This comment has been minimized.

Copy link
@almogdepaz

almogdepaz Mar 31, 2019

Member

broadcast returns error you can do
return b.net.Broadcast(miner.IncomingAtxProtocol, buf)

@@ -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 {

This comment has been minimized.

Copy link
@almogdepaz

almogdepaz Mar 31, 2019

Member

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 {

This comment has been minimized.

Copy link
@almogdepaz

almogdepaz Mar 31, 2019

Member

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
}

This comment has been minimized.

Copy link
@almogdepaz

almogdepaz Mar 31, 2019

Member

addAtxToLayer and db.addAtxToNodeId can fail
we should handle those errors so we wont endup with atx's that are not fully saved

if err != nil {
return errors.New("could not encode layer block ids")
}
db.Atxs.Put(l.ToBytes(), w)

This comment has been minimized.

Copy link
@almogdepaz

almogdepaz Mar 31, 2019

Member

handle error returned from put

return errors.New("could not encode layer block ids")
}
db.Atxs.Put(nodeId.ToBytes(), w)
return nil

This comment has been minimized.

Copy link
@almogdepaz

almogdepaz Mar 31, 2019

Member

handle error returned from put

}

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

This comment has been minimized.

Copy link
@almogdepaz

almogdepaz Mar 31, 2019

Member

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

This comment has been minimized.

Copy link
@moshababo

moshababo Mar 31, 2019

Contributor

Should change to GetPrevAtxId. It's confusing otherwise.

Show resolved Hide resolved activation/activation.go Outdated
Show resolved Hide resolved activation/activation.go Outdated
Sequence: b.GetLastSequence(b.nodeId) + 1,
PrevATX: *prevAtx,
LayerIndex: l,
StartTick: 0, //todo: whatever

This comment has been minimized.

Copy link
@moshababo

moshababo Mar 31, 2019

Contributor

What about EndTick? you want it to be computed (startTick + NIPST difficulty)? If so, perhaps include the computing method.

This comment has been minimized.

Copy link
@moshababo

moshababo Apr 1, 2019

Contributor

Still open.

This comment has been minimized.

Copy link
@antonlerner

antonlerner Apr 1, 2019

Author Member

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{

This comment has been minimized.

Copy link
@moshababo

moshababo Mar 31, 2019

Contributor

Why not using mesh.NewActivationTx? If not useful, perhaps remove it entirely.

This comment has been minimized.

Copy link
@moshababo

moshababo Apr 1, 2019

Contributor

Still open.

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

This comment has been minimized.

Copy link
@moshababo

moshababo Mar 31, 2019

Contributor

Update the protocol string (IncomingTxProtocol -> IncomingAtxProtocol).

This comment has been minimized.

Copy link
@moshababo

moshababo Apr 1, 2019

Contributor

Still open.

Show resolved Hide resolved miner/block_builder.go Outdated
Show resolved Hide resolved miner/block_builder.go Outdated
data.ReportValidation(IncomingTxProtocol, false)
break
}
data.ReportValidation(IncomingTxProtocol, true)

This comment has been minimized.

Copy link
@moshababo

moshababo Mar 31, 2019

Contributor

Where the ATX syntactic validity checks will happen?

This comment has been minimized.

Copy link
@antonlerner

antonlerner Mar 31, 2019

Author Member

TBD, will add a comment

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

This comment has been minimized.

Copy link
@moshababo

moshababo Apr 1, 2019

Contributor

Still open.

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

This comment has been minimized.

Copy link
@moshababo

moshababo Apr 1, 2019

Contributor

Still open.

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

This comment has been minimized.

Copy link
@moshababo

moshababo Apr 1, 2019

Contributor

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?

This comment has been minimized.

Copy link
@moshababo

moshababo Apr 1, 2019

Contributor

Still open.

} else {
atxs, err = decodeAtxIds(ids)
if err != nil {
return errors.New("could not get all blocks from database ")

This comment has been minimized.

Copy link
@moshababo

moshababo Apr 1, 2019

Contributor

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,

This comment has been minimized.

Copy link
@moshababo

moshababo Apr 1, 2019

Contributor

Still open.

data.ReportValidation(IncomingTxProtocol, false)
break
}
data.ReportValidation(IncomingTxProtocol, true)

This comment has been minimized.

Copy link
@moshababo

moshababo Apr 1, 2019

Contributor

Still open.


const DefaultGasLimit = 10
const DefaultGas = 1

const IncomingTxProtocol = "TxGossip"
const AtxProtocol = "AtxGossip"

This comment has been minimized.

Copy link
@moshababo

moshababo Apr 1, 2019

Contributor

Please IncomingTxProtocol as well.

}

func (b Builder) BuildActivationTx(nipst *nipst.NIPST) error {
prevAtx, err := b.GetPrevAtxId(b.nodeId)

This comment has been minimized.

Copy link
@moshababo

moshababo Apr 1, 2019

Contributor

Update the variable name as well (prevAtx -> prevAtxId).

return &atxId, nil
}

func (b *Builder) GetLastSequence(node mesh.NodeId) uint64 {

This comment has been minimized.

Copy link
@moshababo

moshababo Apr 1, 2019

Contributor

Why having all the errors here silent?
(Still open)

@antonlerner antonlerner force-pushed the activation_tx branch from 440d8c5 to 8dd725c Apr 1, 2019

antonlerner added some commits Apr 1, 2019

@antonlerner antonlerner merged commit 4daf5e1 into develop Apr 1, 2019

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@antonlerner antonlerner deleted the activation_tx branch Apr 1, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.