diff --git a/nodebuilder/header/data_root_tuple_root.go b/nodebuilder/header/data_root_tuple_root.go index 539194f915..c30d740b91 100644 --- a/nodebuilder/header/data_root_tuple_root.go +++ b/nodebuilder/header/data_root_tuple_root.go @@ -36,9 +36,9 @@ func padBytes(byt []byte, length int) ([]byte, error) { return tmp, nil } -// To32PaddedHexBytes takes a number and returns its hex representation padded to 32 bytes. +// to32PaddedHexBytes takes a number and returns its hex representation padded to 32 bytes. // Used to mimic the result of `abi.encode(number)` in Ethereum. -func To32PaddedHexBytes(number uint64) ([]byte, error) { +func to32PaddedHexBytes(number uint64) ([]byte, error) { hexRepresentation := strconv.FormatUint(number, 16) // Make sure hex representation has even length. // The `strconv.FormatUint` can return odd length hex encodings. @@ -58,17 +58,17 @@ func To32PaddedHexBytes(number uint64) ([]byte, error) { return paddedBytes, nil } -// DataRootTuple contains the data that will be used to generate the Blobstream data root tuple +// dataRootTuple contains the data that will be used to generate the Blobstream data root tuple // roots. For more information: // https://github.com/celestiaorg/blobstream-contracts/blob/master/src/DataRootTuple.sol -type DataRootTuple struct { +type dataRootTuple struct { height uint64 dataRoot [32]byte } -// EncodeDataRootTuple takes a height and a data root, and returns the equivalent of +// encodeDataRootTuple takes a height and a data root, and returns the equivalent of // `abi.encode(...)` in Ethereum. -// The encoded type is a DataRootTuple, which has the following ABI: +// The encoded type is a dataRootTuple, which has the following ABI: // // { // "components":[ @@ -93,8 +93,8 @@ type DataRootTuple struct { // padding the hex representation of the height padded to 32 bytes concatenated to the data root. // For more information, refer to: // https://github.com/celestiaorg/blobstream-contracts/blob/master/src/DataRootTuple.sol -func EncodeDataRootTuple(height uint64, dataRoot [32]byte) ([]byte, error) { - paddedHeight, err := To32PaddedHexBytes(height) +func encodeDataRootTuple(height uint64, dataRoot [32]byte) ([]byte, error) { + paddedHeight, err := to32PaddedHexBytes(height) if err != nil { return nil, err } @@ -151,13 +151,13 @@ func (s *Service) validateDataRootTupleRootRange(ctx context.Context, start, end // hashDataRootTuples hashes a list of blocks data root tuples, i.e., height, data root and square // size, then returns their merkle root. -func hashDataRootTuples(tuples []DataRootTuple) ([]byte, error) { +func hashDataRootTuples(tuples []dataRootTuple) ([]byte, error) { if len(tuples) == 0 { return nil, fmt.Errorf("cannot hash an empty list of data root tuples") } dataRootEncodedTuples := make([][]byte, 0, len(tuples)) for _, tuple := range tuples { - encodedTuple, err := EncodeDataRootTuple( + encodedTuple, err := encodeDataRootTuple( tuple.height, tuple.dataRoot, ) @@ -192,7 +192,7 @@ func (s *Service) validateDataRootInclusionProofRequest( } // proveDataRootTuples returns the merkle inclusion proof for a height. -func proveDataRootTuples(tuples []DataRootTuple, height int64) (*merkle.Proof, error) { +func proveDataRootTuples(tuples []dataRootTuple, height int64) (*merkle.Proof, error) { if len(tuples) == 0 { return nil, fmt.Errorf("cannot prove an empty list of tuples") } @@ -208,7 +208,7 @@ func proveDataRootTuples(tuples []DataRootTuple, height int64) (*merkle.Proof, e } dataRootEncodedTuples := make([][]byte, 0, len(tuples)) for _, tuple := range tuples { - encodedTuple, err := EncodeDataRootTuple( + encodedTuple, err := encodeDataRootTuple( tuple.height, tuple.dataRoot, ) @@ -223,8 +223,8 @@ func proveDataRootTuples(tuples []DataRootTuple, height int64) (*merkle.Proof, e // fetchDataRootTuples takes an end exclusive range of heights and fetches its // corresponding data root tuples. -func (s *Service) fetchDataRootTuples(ctx context.Context, start, end uint64) ([]DataRootTuple, error) { - tuples := make([]DataRootTuple, 0, end-start) +func (s *Service) fetchDataRootTuples(ctx context.Context, start, end uint64) ([]dataRootTuple, error) { + tuples := make([]dataRootTuple, 0, end-start) for height := start; height < end; height++ { block, err := s.GetByHeight(ctx, height) if err != nil { @@ -233,7 +233,7 @@ func (s *Service) fetchDataRootTuples(ctx context.Context, start, end uint64) ([ if block == nil { return nil, fmt.Errorf("couldn't load block %d", height) } - tuples = append(tuples, DataRootTuple{ + tuples = append(tuples, dataRootTuple{ height: block.Height(), dataRoot: *(*[32]byte)(block.DataHash), }) diff --git a/nodebuilder/header/service_test.go b/nodebuilder/header/service_test.go index 22c2ccc39a..a0fa2efa75 100644 --- a/nodebuilder/header/service_test.go +++ b/nodebuilder/header/service_test.go @@ -105,7 +105,7 @@ func TestTo32PaddedHexBytes(t *testing.T) { for _, test := range tests { t.Run(fmt.Sprintf("number: %d", test.number), func(t *testing.T) { - result, err := To32PaddedHexBytes(test.number) + result, err := to32PaddedHexBytes(test.number) if test.expectError { assert.Error(t, err) } else { @@ -130,7 +130,7 @@ func TestEncodeDataRootTuple(t *testing.T) { require.NoError(t, err) require.NotNil(t, expectedEncoding) - actualEncoding, err := EncodeDataRootTuple(height, *(*[32]byte)(dataRoot)) + actualEncoding, err := encodeDataRootTuple(height, *(*[32]byte)(dataRoot)) require.NoError(t, err) require.NotNil(t, actualEncoding) @@ -141,13 +141,13 @@ func TestEncodeDataRootTuple(t *testing.T) { func TestHashDataRootTuples(t *testing.T) { tests := map[string]struct { - tuples []DataRootTuple + tuples []dataRootTuple expectedHash []byte expectErr bool }{ "empty tuples list": {tuples: nil, expectErr: true}, "valid list of data root tuples": { - tuples: []DataRootTuple{ + tuples: []dataRootTuple{ { height: 1, dataRoot: [32]byte{0x1}, @@ -158,8 +158,8 @@ func TestHashDataRootTuples(t *testing.T) { }, }, expectedHash: func() []byte { - tuple1, _ := EncodeDataRootTuple(1, [32]byte{0x1}) - tuple2, _ := EncodeDataRootTuple(2, [32]byte{0x2}) + tuple1, _ := encodeDataRootTuple(1, [32]byte{0x1}) + tuple2, _ := encodeDataRootTuple(2, [32]byte{0x2}) return merkle.HashFromByteSlices([][]byte{tuple1, tuple2}) }(), @@ -181,7 +181,7 @@ func TestHashDataRootTuples(t *testing.T) { func TestProveDataRootTuples(t *testing.T) { tests := map[string]struct { - tuples []DataRootTuple + tuples []dataRootTuple height int64 expectedProof merkle.Proof expectErr bool @@ -189,7 +189,7 @@ func TestProveDataRootTuples(t *testing.T) { "empty tuples list": {tuples: nil, expectErr: true}, "strictly negative height": { height: -1, - tuples: []DataRootTuple{ + tuples: []dataRootTuple{ { height: 1, dataRoot: [32]byte{0x1}, @@ -198,7 +198,7 @@ func TestProveDataRootTuples(t *testing.T) { expectErr: true, }, "non consecutive list of tuples at the beginning": { - tuples: []DataRootTuple{ + tuples: []dataRootTuple{ { height: 1, dataRoot: [32]byte{0x1}, @@ -215,7 +215,7 @@ func TestProveDataRootTuples(t *testing.T) { expectErr: true, }, "non consecutive list of tuples in the middle": { - tuples: []DataRootTuple{ + tuples: []dataRootTuple{ { height: 1, dataRoot: [32]byte{0x1}, @@ -240,7 +240,7 @@ func TestProveDataRootTuples(t *testing.T) { expectErr: true, }, "non consecutive list of tuples at the end": { - tuples: []DataRootTuple{ + tuples: []dataRootTuple{ { height: 1, dataRoot: [32]byte{0x1}, @@ -257,7 +257,7 @@ func TestProveDataRootTuples(t *testing.T) { expectErr: true, }, "duplicate height at the beginning": { - tuples: []DataRootTuple{ + tuples: []dataRootTuple{ { height: 1, dataRoot: [32]byte{0x1}, @@ -274,7 +274,7 @@ func TestProveDataRootTuples(t *testing.T) { expectErr: true, }, "duplicate height in the middle": { - tuples: []DataRootTuple{ + tuples: []dataRootTuple{ { height: 1, dataRoot: [32]byte{0x1}, @@ -295,7 +295,7 @@ func TestProveDataRootTuples(t *testing.T) { expectErr: true, }, "duplicate height at the end": { - tuples: []DataRootTuple{ + tuples: []dataRootTuple{ { height: 1, dataRoot: [32]byte{0x1}, @@ -313,7 +313,7 @@ func TestProveDataRootTuples(t *testing.T) { }, "valid proof": { height: 3, - tuples: []DataRootTuple{ + tuples: []dataRootTuple{ { height: 1, dataRoot: [32]byte{0x1}, @@ -332,10 +332,10 @@ func TestProveDataRootTuples(t *testing.T) { }, }, expectedProof: func() merkle.Proof { - encodedTuple1, _ := EncodeDataRootTuple(1, [32]byte{0x1}) - encodedTuple2, _ := EncodeDataRootTuple(2, [32]byte{0x2}) - encodedTuple3, _ := EncodeDataRootTuple(3, [32]byte{0x3}) - encodedTuple4, _ := EncodeDataRootTuple(4, [32]byte{0x4}) + encodedTuple1, _ := encodeDataRootTuple(1, [32]byte{0x1}) + encodedTuple2, _ := encodeDataRootTuple(2, [32]byte{0x2}) + encodedTuple3, _ := encodeDataRootTuple(3, [32]byte{0x3}) + encodedTuple4, _ := encodeDataRootTuple(4, [32]byte{0x4}) _, proofs := merkle.ProofsFromByteSlices([][]byte{encodedTuple1, encodedTuple2, encodedTuple3, encodedTuple4}) return *proofs[2] }(),