diff --git a/sharding/collation.go b/sharding/collation.go index ceff9e6f8..1b9e9a890 100644 --- a/sharding/collation.go +++ b/sharding/collation.go @@ -122,9 +122,11 @@ func (c *Collation) CalculateChunkRoot() { // some salt, which is appended to each chunk in the collation body before it // is hashed. func (c *Collation) CalculatePOC(salt []byte) common.Hash { - body := make([]byte, len(c.body)) + body := make([]byte, 0, len(c.body)*(1+len(salt))) + + // TODO: Use 32 byte chunks instead of a single byte for _, chunk := range c.body { - body = append(body, append(salt, chunk)...) // add salt to each chunk. + body = append(append(body, salt...), chunk) } if len(c.body) == 0 { body = salt @@ -139,23 +141,6 @@ func BytesToChunks(body []byte) Chunks { return Chunks(body) } -// ConvertBackToTx converts raw blobs back to their original transactions. -func ConvertBackToTx(rawBlobs []utils.RawBlob) ([]*types.Transaction, error) { - - blobs := make([]*types.Transaction, len(rawBlobs)) - - for i := 0; i < len(rawBlobs); i++ { - - blobs[i] = types.NewTransaction(0, common.HexToAddress("0x"), nil, 0, nil, nil) - - err := utils.ConvertFromRawBlob(&rawBlobs[i], blobs[i]) - if err != nil { - return nil, fmt.Errorf("Creation of transactions from raw blobs failed: %v", err) - } - } - return blobs, nil -} - // convertTxToRawBlob transactions into RawBlobs. This step encodes transactions uses RLP encoding func convertTxToRawBlob(txs []*types.Transaction) ([]*utils.RawBlob, error) { blobs := make([]*utils.RawBlob, len(txs)) diff --git a/sharding/collation_test.go b/sharding/collation_test.go index 5d74907c0..a688bd5fe 100644 --- a/sharding/collation_test.go +++ b/sharding/collation_test.go @@ -308,3 +308,17 @@ func BenchmarkSerializeRoundtrip100(b *testing.B) { func BenchmarkSerializeRoundtrip1000(b *testing.B) { runSerializeRoundtrip(b, 1000) } + +func BenchmarkCalculatePOC(b *testing.B) { + body := make([]byte, 300) + rand.Read(body) + + collation := NewCollation(&CollationHeader{}, body, nil) + + salt := make([]byte, 20) + rand.Read(salt) + + for i := 0; i < b.N; i++ { + collation.CalculatePOC(salt) + } +}