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

Fixed seed conditions and added tests for applying transactions. #126

Merged
merged 12 commits into from
Jul 18, 2019

Conversation

losfair
Copy link
Contributor

@losfair losfair commented Jul 10, 2019

No description provided.

@losfair losfair requested a review from iwasaki-kenta July 10, 2019 11:08
tx.go Outdated
return &tx
}

func AttachSenderToTransactionInPlace(sender *skademlia.Keypair, tx *Transaction, parents ...*Transaction) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename to AppendSenderToTransaction to imply that it in-place modifies the transaction provided. Also please provide documentation on these functions.

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 don't think Append and Attach really imply this difference.

Copy link
Contributor

Choose a reason for hiding this comment

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

The Append prefix pattern, I am taking it as a style guideline from the fasthttp, fastjson etc libraries that provide functions which modify some pointer in-place.

tx.go Outdated
t.SeedLen = byte(prefixLen(t.Seed[:]))
_, err = hasher.Write(t.Sender[:])
if err != nil {
panic(err) // should never happen
Copy link
Contributor

Choose a reason for hiding this comment

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

If it should never happen, then write instead _, _ = hasher.Write(t.Sender[:]).

Copy link
Contributor

Choose a reason for hiding this comment

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

Same goes for other error-check statements within rehash().

Copy link
Contributor

Choose a reason for hiding this comment

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

i would put log even in case it will "never" 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.

If something that should never happen does happen, it should be a fatal error. Panic in this case.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd argue just explicitly ignoring via _, _ = hasher.Write(t.Sender[:]). The documentation states that an error will never be thrown. A panic nor an error in this case should never have to occur. If needed, a comment can be appended to emphasize this.

@iwasaki-kenta
Copy link
Contributor

FIXME(@iwasaki-kenta): Whitepaper must be updated with respect to the new seed conditions.

@a-urth
Copy link
Contributor

a-urth commented Jul 18, 2019

One more thing on topic about pointers vs values. It would've been good to have benchmark if we care about speed. Because every struct value which is not passed by pointer is allocated on the stack which is much faster then the heap. So maybe its actually cheaper to allocate new struct for each function call on the stack then to allocate it on the heap and then resolve pointer (which is also not for free).

@iwasaki-kenta
Copy link
Contributor

One more thing on topic about pointers vs values. It would've been good to have benchmark if we care about speed. Because every struct value which is not passed by pointer is allocated on the stack which is much faster then the heap. So maybe its actually cheaper to allocate new struct for each function call on the stack then to allocate it on the heap and then resolve pointer (which is also not for free).

I completely agree as well. Originally transactions were only heap-allocated should they be added to the graph of a node.

We should setup performance regression tests in the near future. I will also adjust some styling in this PR after merging it in to master given that all tests pass and nothing breaks.

@iwasaki-kenta iwasaki-kenta merged commit 7c6735b into master Jul 18, 2019
@iwasaki-kenta iwasaki-kenta deleted the fix/seed-condition branch July 18, 2019 05:56
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.

3 participants