From a1941432f7e318eeb2552dcf554b2e53067588c1 Mon Sep 17 00:00:00 2001 From: Terence Tsao Date: Thu, 24 May 2018 14:58:34 -0700 Subject: [PATCH 1/3] sharding: Serialize function shouldn't take pointer receiver --- sharding/collation.go | 41 ++++++++++---------------------------- sharding/collation_test.go | 2 +- 2 files changed, 11 insertions(+), 32 deletions(-) diff --git a/sharding/collation.go b/sharding/collation.go index 3ce4b55e3387..6c9c45340b7c 100644 --- a/sharding/collation.go +++ b/sharding/collation.go @@ -111,26 +111,6 @@ func (c *Collation) CalculateChunkRoot() { c.header.data.ChunkRoot = &chunkRoot } -// CreateRawBlobs creates raw blobs from transactions. -func (c Collation) CreateRawBlobs() ([]*utils.RawBlob, error) { - - // It does not skip evm execution by default - blobs := make([]*utils.RawBlob, len(c.transactions)) - for i := 0; i < len(c.transactions); i++ { - - err := error(nil) - blobs[i], err = utils.NewRawBlob(c.transactions[i], false) - - if err != nil { - return nil, fmt.Errorf("Creation of raw blobs from transactions failed: %v", err) - } - - } - - return blobs, nil - -} - // ConvertBackToTx converts raw blobs back to their original transactions. func ConvertBackToTx(rawBlobs []utils.RawBlob) ([]*types.Transaction, error) { @@ -149,29 +129,28 @@ func ConvertBackToTx(rawBlobs []utils.RawBlob) ([]*types.Transaction, error) { } -// Serialize method serializes the collation body to a byte array. -func (c *Collation) Serialize() ([]byte, error) { - - blobs, err := c.CreateRawBlobs() +// Serialize method serializes the input transactions +// and returns the chunks in byte arrays. +func Serialize(txs []*types.Transaction) ([]byte, error) { - if err != nil { - return nil, fmt.Errorf("%v", err) + blobs := make([]*utils.RawBlob, len(txs)) + for i := 0; i < len(txs); i++ { + err := error(nil) + blobs[i], err = utils.NewRawBlob(txs[i], false) + if err != nil { + return nil, fmt.Errorf("%v", err) + } } - serializedTx, err := utils.Serialize(blobs) - if err != nil { return nil, fmt.Errorf("%v", err) } if int64(len(serializedTx)) > collationSizelimit { - return nil, fmt.Errorf("The serialized body exceeded the collation size limit: %v", serializedTx) - } return serializedTx, nil - } // Deserialize takes a byte array and converts its back to its original transactions. diff --git a/sharding/collation_test.go b/sharding/collation_test.go index c0e4cb7355b0..cca9d904d124 100644 --- a/sharding/collation_test.go +++ b/sharding/collation_test.go @@ -56,7 +56,7 @@ func TestSerialize_Deserialize(t *testing.T) { tx := c.transactions - results, err := c.Serialize() + results, err := Serialize(tx) if err != nil { t.Errorf("Unable to Serialize transactions, %v", err) From 5e0596bd7a89599a5b5afd5418c6a5d4fbe06109 Mon Sep 17 00:00:00 2001 From: Terence Tsao Date: Thu, 24 May 2018 17:18:55 -0700 Subject: [PATCH 2/3] sharding: changed names to be sharding specific --- sharding/collation.go | 11 ++++++----- sharding/collation_test.go | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/sharding/collation.go b/sharding/collation.go index 6c9c45340b7c..2275e89ab188 100644 --- a/sharding/collation.go +++ b/sharding/collation.go @@ -129,9 +129,9 @@ func ConvertBackToTx(rawBlobs []utils.RawBlob) ([]*types.Transaction, error) { } -// Serialize method serializes the input transactions -// and returns the chunks in byte arrays. -func Serialize(txs []*types.Transaction) ([]byte, error) { +// Serialize method serializes the input tx +// and returns the blobs in byte array. +func SerializeTxToBlob(txs []*types.Transaction) ([]byte, error) { blobs := make([]*utils.RawBlob, len(txs)) for i := 0; i < len(txs); i++ { @@ -153,8 +153,9 @@ func Serialize(txs []*types.Transaction) ([]byte, error) { return serializedTx, nil } -// Deserialize takes a byte array and converts its back to its original transactions. -func Deserialize(serialisedBlob []byte) (*[]*types.Transaction, error) { +// DeserializeBlobToTx takes byte array blob and converts it back +// to original txs and returns the txs in tx array. +func DeserializeBlobToTx(serialisedBlob []byte) (*[]*types.Transaction, error) { deserializedBlobs, err := utils.Deserialize(serialisedBlob) if err != nil { diff --git a/sharding/collation_test.go b/sharding/collation_test.go index cca9d904d124..f3c896e2bfef 100644 --- a/sharding/collation_test.go +++ b/sharding/collation_test.go @@ -56,13 +56,13 @@ func TestSerialize_Deserialize(t *testing.T) { tx := c.transactions - results, err := Serialize(tx) + results, err := SerializeTxToBlob(tx) if err != nil { t.Errorf("Unable to Serialize transactions, %v", err) } - deserializedTxs, err := Deserialize(results) + deserializedTxs, err := DeserializeBlobToTx(results) if err != nil { t.Errorf("Unable to deserialize collation body, %v", err) From 6ecf1249378619effb637901bcbd4df4f3fa5bff Mon Sep 17 00:00:00 2001 From: Terence Tsao Date: Thu, 24 May 2018 17:24:58 -0700 Subject: [PATCH 3/3] sharding: fixed starting name to comply with GoDoc --- sharding/collation.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sharding/collation.go b/sharding/collation.go index 2275e89ab188..e7ec5104a286 100644 --- a/sharding/collation.go +++ b/sharding/collation.go @@ -129,7 +129,7 @@ func ConvertBackToTx(rawBlobs []utils.RawBlob) ([]*types.Transaction, error) { } -// Serialize method serializes the input tx +// SerializeTxToBlob method serializes the input tx // and returns the blobs in byte array. func SerializeTxToBlob(txs []*types.Transaction) ([]byte, error) {