mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-03 08:37:37 +00:00
perf improvements to CalculatePOC (#182)
Sharding: proof of custody performance improvements Former-commit-id: 6a41b5031298579c78d848277fbdff77de27b5f3 [formerly 31a818a367d311f8c7021b9a6b5cad986e53baf3] Former-commit-id: 2c992bf3b2c98573db021f46680a48ccc632f25b
This commit is contained in:
parent
f32f7ba36c
commit
ad291e93f6
@ -122,9 +122,11 @@ func (c *Collation) CalculateChunkRoot() {
|
|||||||
// some salt, which is appended to each chunk in the collation body before it
|
// some salt, which is appended to each chunk in the collation body before it
|
||||||
// is hashed.
|
// is hashed.
|
||||||
func (c *Collation) CalculatePOC(salt []byte) common.Hash {
|
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 {
|
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 {
|
if len(c.body) == 0 {
|
||||||
body = salt
|
body = salt
|
||||||
@ -139,23 +141,6 @@ func BytesToChunks(body []byte) Chunks {
|
|||||||
return Chunks(body)
|
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
|
// convertTxToRawBlob transactions into RawBlobs. This step encodes transactions uses RLP encoding
|
||||||
func convertTxToRawBlob(txs []*types.Transaction) ([]*utils.RawBlob, error) {
|
func convertTxToRawBlob(txs []*types.Transaction) ([]*utils.RawBlob, error) {
|
||||||
blobs := make([]*utils.RawBlob, len(txs))
|
blobs := make([]*utils.RawBlob, len(txs))
|
||||||
|
@ -308,3 +308,17 @@ func BenchmarkSerializeRoundtrip100(b *testing.B) {
|
|||||||
func BenchmarkSerializeRoundtrip1000(b *testing.B) {
|
func BenchmarkSerializeRoundtrip1000(b *testing.B) {
|
||||||
runSerializeRoundtrip(b, 1000)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user