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

Blob Serialisation #92

Merged
merged 37 commits into from
May 17, 2018
Merged

Conversation

nisdas
Copy link
Member

@nisdas nisdas commented Apr 18, 2018

Objectives :

nisdas pushed a commit to nisdas/geth-sharding that referenced this pull request Apr 18, 2018
)

func (c *collationbody) validateBody() bool {
return len(c) < 2^20 && len(c) > 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Inline magic numbers like this aren't understood by outside viewers. Please store in vars called maxcollationsize, mincollationsize, or another sort of construct.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, will put a variable in place and maybe move all the constants to config.go

Copy link
Member

Choose a reason for hiding this comment

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

I left a comment on the design as well, but this would never consider a body valid when the len(cb) == 2^20 i.e. when the collation body is exactly 1 MiB

return len(c) < 2^20 && len(c) > 0
}

func createChunks(c collationbody) {
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 rather have a different name than c for this variable. It reads nicer if we call the variable collationBody or something like that as I can understand line 28 immediately upon the first read.

Copy link
Member

Choose a reason for hiding this comment

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

It is go convention to prefer shortest variable name for the given context.
If anything, we could extend this name to cb and still understand that it is the collation body.

return len(c) < 2^20 && len(c) > 0
}

func createChunks(c collationbody) {
Copy link
Member

Choose a reason for hiding this comment

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

It is go convention to prefer shortest variable name for the given context.
If anything, we could extend this name to cb and still understand that it is the collation body.

fmt.Errorf("Error %v", err)
}
if !validCollation {
fmt.Errorf("Error %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

This would be nil?

)

func (c *collationbody) validateBody() bool {
return len(c) < 2^20 && len(c) > 0
Copy link
Member

Choose a reason for hiding this comment

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

I left a comment on the design as well, but this would never consider a body valid when the len(cb) == 2^20 i.e. when the collation body is exactly 1 MiB

@terencechain terencechain self-requested a review April 19, 2018 18:34
nisdas pushed a commit to nisdas/geth-sharding that referenced this pull request Apr 22, 2018
nisdas pushed a commit to nisdas/geth-sharding that referenced this pull request Apr 22, 2018
nisdas pushed a commit to nisdas/geth-sharding that referenced this pull request Apr 22, 2018
type collationbody []byte

var (
collationsizelimit = int64(2 ^ 20)
Copy link
Member

Choose a reason for hiding this comment

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

This is bitwise XOR and this evaluates to 22

@rauljordan
Copy link
Contributor

Update on this @nisdas ?

@prestonvanloon
Copy link
Member

@rauljordan we had some discussion in gitter about changing this a bit.
https://gitter.im/prysmaticlabs/geth-sharding?at=5adcc202109bb04332ebae14

@nisdas
Copy link
Member Author

nisdas commented Apr 24, 2018

@rauljordan , Preston and I had a discussion about this on the changes to make. Which would be a bit different from how it is being implemented now. I will push something up soon

nisdas pushed a commit to nisdas/geth-sharding that referenced this pull request May 1, 2018
nisdas pushed a commit to nisdas/geth-sharding that referenced this pull request May 2, 2018
nisdas pushed a commit to nisdas/geth-sharding that referenced this pull request May 2, 2018
nisdas pushed a commit to nisdas/geth-sharding that referenced this pull request May 2, 2018
nisdas pushed a commit to nisdas/geth-sharding that referenced this pull request May 2, 2018

} else {
terminalIndex := int64(collationbody[(i-1)*chunkSize])
tempbody = append(tempbody, collationbody[((i-1)*chunkSize+1):((i-1)*chunkSize+2+terminalIndex)]...)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shorten line length plz. Perhaps abstract into some more vars?


for i := int64(1); i <= chunksNumber; i++ {

if reflect.TypeOf(collationbody[(i-1)*chunkSize]) == reflect.TypeOf(indicatorByte) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shorten this if condition. Perhaps explain with some more comments?

}
// Appends indicator bytes to terminal-chunks , and if the index of the chunk delimiter is non-zero adds it to the chunk
indicatorByte[0] = byte(terminalLength)
tempbody = append(tempbody, append(indicatorByte, cb[chunksNumber*chunkDataSize:(chunksNumber*chunkDataSize)+(terminalLength+1)]...)...)
Copy link
Contributor

Choose a reason for hiding this comment

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

This line is too long. Too much is going on here and hard to keep track as a reader.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah agreed, I will try to abstract and make the code more readable. Also will add comments to explain the serialization flow better


}
indicatorByte[0] = byte(chunkDataSize)
tempbody = append(tempbody, append(indicatorByte, cb[(chunksNumber-1)*chunkDataSize:chunksNumber*chunkDataSize]...)...)
Copy link
Contributor

Choose a reason for hiding this comment

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

Too long, simplify and explain a little.

Copy link
Member

@prestonvanloon prestonvanloon left a comment

Choose a reason for hiding this comment

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

I'm a bit worried that this util is a bit cumbersome to use.

Can we use an approach similar to the JSON marshaller?

If you recall we discussed something that looked like this

unc Marshal(v []interface{}) ([]byte, error)
func Unmarshal(data []byte, v []interface{}) error

See: https://blog.golang.org/json-and-go

I think that interface receiver approach you have taken will be hard to use and your tests might prove that too.

With the marshal method it would be trivial to use and familiar to go developers.

nisdas pushed a commit to nisdas/geth-sharding that referenced this pull request May 3, 2018
nisdas pushed a commit to nisdas/geth-sharding that referenced this pull request May 3, 2018
nisdas pushed a commit to nisdas/geth-sharding that referenced this pull request May 3, 2018
nisdas pushed a commit to nisdas/geth-sharding that referenced this pull request May 3, 2018
nisdas pushed a commit to nisdas/geth-sharding that referenced this pull request May 3, 2018
nisdas pushed a commit to nisdas/geth-sharding that referenced this pull request May 3, 2018
nisdas pushed a commit to nisdas/geth-sharding that referenced this pull request May 3, 2018
nisdas pushed a commit to nisdas/geth-sharding that referenced this pull request May 3, 2018
nisdas pushed a commit to nisdas/geth-sharding that referenced this pull request May 3, 2018
nisdas pushed a commit to nisdas/geth-sharding that referenced this pull request May 3, 2018
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: abb3b3d0213daf4b6e84c880cf202bf91d04d086 [formerly d3e6aad]
Former-commit-id: 1185e61
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: 2047d553c3226550d07852d91352ba5287b86f6f [formerly 1257adb]
Former-commit-id: 75ad116
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: 4d236b8b6a8b9d242beaeb2c035d0fae25fb4f63 [formerly 0a9b7aa]
Former-commit-id: c7e62ad
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: f4afd07be086b843f857febbe127396eadfa0406 [formerly 5c8f51b]
Former-commit-id: 122da75
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: 1a7affe598d4b93b0983efcfdfb48d2d6b649bcf [formerly 7ec6f8b]
Former-commit-id: beef303
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: edbf5bd3d11b46f463bf26027178fb7d06fc13fb [formerly 73e4692]
Former-commit-id: ca76a1e
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: 85e659f3ea43c983f8df54ab8a3150a560b2dbf8 [formerly 2c0a181]
Former-commit-id: 0198766
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: 553d0fc1c4e99d0c3216bcb624c9f05cdbb07e1f [formerly ecebff2]
Former-commit-id: 476e50d
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: 45ebe18e2281496741d6b08fae04419a55f008c6 [formerly 5473045]
Former-commit-id: 4df6d79
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: 0c678a1778c83476c688a1bf1353aaba8cde10dc [formerly 7c5f280]
Former-commit-id: 34566a7
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: 3eb0cfbf6c9c2a7ec9619d2f93c1be8ca8b670c9 [formerly 108d9e2]
Former-commit-id: d128c55
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: 7bc42f4bf78f03ddecd07d309699e5771bf2e501 [formerly 9367511]
Former-commit-id: 0dd0567
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: b59692c3ccb912131f0087a3f19cbfa88886a6e5 [formerly 7e7497f]
Former-commit-id: 5f5e64a
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: 143739c759abdd01fb74539a85c5cd4abf5d1b79 [formerly d375cec]
Former-commit-id: 302a456
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: 24cbfacd178e77721dc50a36bec4d8c8aa0ff1cf [formerly ff1f6be]
Former-commit-id: 1540df8
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: eeb3e8626b2956c37b5730e4ea70898cb9a70c70 [formerly e93169c]
Former-commit-id: 0ccbdb8
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: 5901594a02b82d0cd11e85593f7021d0cb0a6d62 [formerly dd57899]
Former-commit-id: 047157d
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: 08366f9b544217367dac936d2bf651a26f3a05aa [formerly 01ac4ab]
Former-commit-id: 4dcaf51
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: 7f58a5eb03fa6347ff5fae94443bf896f9db0486 [formerly ba599c2]
Former-commit-id: 13abf7e
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: a18ff8c27d7ec87cd38e112f6322a753fb892307 [formerly 228bddf]
Former-commit-id: 375f57b
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: 4feb34fa32cf0a3495a4fc8f8feb6336b567fc15 [formerly 9e5f852]
Former-commit-id: df3014b
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: 71f037aae070dcc5761f06591e889b31075c7b40 [formerly 8158b93]
Former-commit-id: b6a4bc4
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: 5b0e344d84b8d1ff8d12205376c9ae8715c7089e [formerly fe3697b]
Former-commit-id: dfd0123
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: be930e31eea223934f0fa9aea28e306817746bc1 [formerly e8988d0]
Former-commit-id: 6d2dbb0
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: a87c10e58acc0af3364f1de4b67856e084cd8a5a [formerly cef802b]
Former-commit-id: 5b463c6
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: 09bb5072963354b735d5c0c22c9d43761cab8234 [formerly 907a147]
Former-commit-id: b3afc33
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: 0417e770170d2ca1beca38ebea578481f7879a14 [formerly 41e3fc2]
Former-commit-id: 9898b39
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: cb11c83f0d32b7e8c383c974378ddbdb756ecbe4 [formerly a88b20f]
Former-commit-id: cf5df84
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Former-commit-id: 25b3147ba8e7a67a7ed0215ea0e382699523d876 [formerly 72089a1]
Former-commit-id: 2cea947
prestonvanloon pushed a commit that referenced this pull request Jul 22, 2018
Blob Serialisation

Former-commit-id: 35783a1d0e0c2aa1365b377fd96cedb1ce75ebeb [formerly 524c277]
Former-commit-id: ff173d7
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

4 participants