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

inverted control between nipst builder and atx builder #806

Merged
merged 20 commits into from Apr 15, 2019

Conversation

antonlerner
Copy link
Contributor

No description provided.

if err != nil {
return err
}
//todo: should we do something about it? wait for something?
Copy link
Member

Choose a reason for hiding this comment

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

Is this todo in the right place? Seems like it should be here 👇?
daea588#diff-1ba4cf64f19ae66633cb8b7ca7158fabR103

@@ -94,6 +96,50 @@ func (m *ActivationDb) CalcActiveSetFromView(a *types.ActivationTx) (uint32, err

}

const NIPST_LAYERTIME = 1000

func (db *ActivationDb) ValidateAtx(atx *types.ActivationTx) error {
Copy link
Member

Choose a reason for hiding this comment

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

There are inconsistent receiver names in this module. These methods are different than the rest:

func (m *ActivationDb) ProcessBlockATXs(blk *types.Block) {
func (m *ActivationDb) CalcActiveSetFromView(a *types.ActivationTx) (uint32, error) {

@@ -94,6 +96,50 @@ func (m *ActivationDb) CalcActiveSetFromView(a *types.ActivationTx) (uint32, err

}

const NIPST_LAYERTIME = 1000
Copy link
Member

Choose a reason for hiding this comment

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

Use CamelCase

@antonlerner antonlerner marked this pull request as ready for review April 14, 2019 12:42
}
prevAtxIds, err := db.GetNodeAtxIds(atx.NodeId)
if err == nil && len(prevAtxIds) > 0 {
prevAtx, err := db.GetAtx(prevAtxIds[len(prevAtxIds)])
Copy link
Member

Choose a reason for hiding this comment

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

prevAtxIds[len(prevAtxIds)] will always panic.

If you have a 3 element slice (len()==3) it has elements 0, 1 and 2, but never 3 (or its length would be 4).

if err == nil && len(prevAtxIds) > 0 {
prevAtx, err := db.GetAtx(prevAtxIds[len(prevAtxIds)])
if err == nil {
if prevAtx.Sequence == atx.Sequence {
Copy link
Member

Choose a reason for hiding this comment

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

We're only checking the last ATX - does db.GetNodeAtxIds return a sorted list?

Copy link
Member

Choose a reason for hiding this comment

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

We don't check for a lower sequence number (e.g. 1 -> 2 -> 3 -> 2 would pass validation).

Copy link
Member

Choose a reason for hiding this comment

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

We don't validate the PrevATXId field at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

returns a list of received atx's sorted by the time they were received

Copy link
Member

Choose a reason for hiding this comment

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

The way I think this should be implemented is by storing the nextATX on the prev ATX (doubly linked list).

Then, to validate, you go to the linked prevATX and validate that its nextATX is blank and that the sequence numbers between those two are correct (current is greater than previous).

Copy link
Member

Choose a reason for hiding this comment

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

Of course, we'd also need to verify that if no prevATX was linked - then no other ATXs exist for that miner ID.

}
}
} else {
if prevAtxIds == nil && atx.PrevATXId != types.EmptyAtx {
Copy link
Member

Choose a reason for hiding this comment

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

Replace prevAtxIds == nil with len(prevAtxIds) == 0?

This would better convey the intention and also be safer (what If someone makes db.GetNodeAtxIds return an empty slice instead of nil when nothing is found?).

Copy link
Member

Choose a reason for hiding this comment

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

More importantly - you're not checking for the opposite case, where someone doesn't link to a previous ATX, but one exists.

Copy link
Member

Choose a reason for hiding this comment

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

BTW, this is the biggest thing we need to defend against, since it allows working on multiple ATXs concurrently.

if err != nil {
return fmt.Errorf("positioning atx not found")
}
if !posAtx.Valid {
Copy link
Member

Choose a reason for hiding this comment

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

An ATX in the database should always be valid, no?

Copy link
Member

Choose a reason for hiding this comment

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

after our discussion right now, I think we should keep invalid ATXs as well

@noamnelke noamnelke merged commit 1c13cc1 into develop Apr 15, 2019
@noamnelke noamnelke deleted the poet_challange branch June 30, 2019 06:47
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