-
Notifications
You must be signed in to change notification settings - Fork 2
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
85-block-extra-data #88
Conversation
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.
Interested in what the use case of the extra data is? I know there is some analogue in BTC. Also, why are we enforcing a block size now?
@@ -28,6 +27,9 @@ type BlockHeader struct { | |||
Time uint32 | |||
// Nonce starts at 0 and increments by 1 for every hash when mining | |||
Nonce uint64 | |||
// ExtraData is an extra field that can be filled with arbitrary data to | |||
// be stored in the block | |||
ExtraData []byte |
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 know there is some analogue to this in bitcoin. Interested, why are we adding it to our chain?
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 was thinking its a standard blockchain feature, lets you store data for "eternity" and will potentially help us with future applications of our blockchain.
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 we make this an array to indicate that it should be size-limited? (can change later too).
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.
This is what chad and i were talking about on slack, I think we decided to not limit any size for now. I made a ticket for it.
blockchain/block.go
Outdated
|
||
return buf | ||
} | ||
|
||
// Len returns the length in bytes of the BlockHeader. | ||
func (bh *BlockHeader) Len() int { | ||
l := 2*(32/8) + 64/8 + 2*HashLen |
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.
unsafe
doesn't seem ideal, but isn't there some notion of sizeof
in golang?https://stackoverflow.com/questions/26975738/how-to-get-memory-size-of-variable
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.
been looking in to this, unsafe.Sizeof causes some issues because in the ExtraData byte array, Sizeof returns the size of the slice descriptor, not the size of the memory referenced by the slice which is what we want as we are looking for the length when marshalled.
Statically setting the length here should be safe if we have tests that will fail once someone messes with it.
blockchain/block.go
Outdated
BlockHeaderLen = 2*(32/8) + 64/8 + 2*HashLen | ||
// MaxBlockSize is the maximum size of a block in bytes when marshaled | ||
// (about 250K). | ||
MaxBlockSize = 1 << 18 |
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.
Block size is busy blowing the bitcoin universe up - are we sure we want to enforce it?
- https://medium.com/@olivierjanss/the-solution-to-the-block-size-debate-42c3814ff481
- https://www.bitcoinunlimited.info/
Did you guys discuss this on Saturday? I'm game if we're consciously making the decision.
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.
Bringing this to slack
blockchain/validation_test.go
Outdated
|
||
valid, code := bc.ValidGenesisBlock(gb) | ||
|
||
if valid { |
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.
Use assert
if we can? 😄
… are now returning len(x.marshal())
@@ -28,6 +27,9 @@ type BlockHeader struct { | |||
Time uint32 | |||
// Nonce starts at 0 and increments by 1 for every hash when mining | |||
Nonce uint64 | |||
// ExtraData is an extra field that can be filled with arbitrary data to | |||
// be stored in the block | |||
ExtraData []byte |
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 we make this an array to indicate that it should be size-limited? (can change later too).
blockchain/validation.go
Outdated
@@ -73,7 +73,7 @@ const ( | |||
BadGenesisBlockNumber | |||
// BadGenesisTarget is returned when the genesis block's target is invalid. | |||
BadGenesisTarget | |||
// BadGenesisTime is returned when teh gensis block's time is invalid. | |||
// BadGenesisTime is returned when the gensis block's time is invalid. |
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.
there's another typo here lol (gensis -> genesis)
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.
Gensyscalls
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.
Wow! Great work!
l += t.Len() | ||
} | ||
return l | ||
return len(b.Marshal()) |
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.
Nice
blockchain/validation.go
Outdated
@@ -73,7 +73,7 @@ const ( | |||
BadGenesisBlockNumber | |||
// BadGenesisTarget is returned when the genesis block's target is invalid. | |||
BadGenesisTarget | |||
// BadGenesisTime is returned when teh gensis block's time is invalid. | |||
// BadGenesisTime is returned when the gensis block's time is invalid. |
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.
Gensyscalls
@@ -190,6 +190,7 @@ func ValidCloudBase(t *Transaction) (bool, CloudBaseTransactionCode) { | |||
|
|||
// ValidGenesisBlock checks whether a block is a valid genesis block. | |||
func (bc *BlockChain) ValidGenesisBlock(gb *Block) (bool, GenesisBlockCode) { | |||
|
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.
This is my favorite line
if b == nil { | ||
return false, NilBlock | ||
} | ||
|
||
// Check if the block is the genesis block | ||
// Check if the block is the genesis block. |
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.
Good catch
@david-julien Does this build for you locally? I get:
Maybe why Travis is failing |
No description provided.