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

Fix: pfb count computing #19

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions pkg/indexer/decode/handle/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// MsgPayForBlobs pays for the inclusion of a blob in the block.
func MsgPayForBlobs(level types.Level, m *appBlobTypes.MsgPayForBlobs) (storageTypes.MsgType, []storage.AddressWithType, []storage.Namespace, int64, error) {
var blobsSize int64
namespaces := make([]storage.Namespace, len(m.Namespaces))
uniqueNs := make(map[string]*storage.Namespace)

for nsI, ns := range m.Namespaces {
if len(m.BlobSizes) < nsI {
Expand All @@ -26,14 +26,24 @@ func MsgPayForBlobs(level types.Level, m *appBlobTypes.MsgPayForBlobs) (storageT
appNS := namespace.Namespace{Version: ns[0], ID: ns[1:]}
size := int64(m.BlobSizes[nsI])
blobsSize += size
namespaces[nsI] = storage.Namespace{
namespace := storage.Namespace{
FirstHeight: level,
Version: appNS.Version,
NamespaceID: appNS.ID,
Size: size,
PfbCount: 1,
Reserved: appNS.IsReserved(),
}
if n, ok := uniqueNs[namespace.String()]; ok {
n.Size += size
} else {
uniqueNs[namespace.String()] = &namespace
}
}

namespaces := make([]storage.Namespace, 0, len(uniqueNs))
for _, namespace := range uniqueNs {
namespaces = append(namespaces, *namespace)
}

addresses, err := createAddresses(addressesData{
Expand Down
76 changes: 74 additions & 2 deletions pkg/indexer/decode/handle/test/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
package handle_test

import (
"testing"

"github.com/celenium-io/celestia-indexer/internal/storage"
storageTypes "github.com/celenium-io/celestia-indexer/internal/storage/types"
"github.com/celenium-io/celestia-indexer/internal/test_suite"
testsuite "github.com/celenium-io/celestia-indexer/internal/test_suite"
"github.com/celenium-io/celestia-indexer/pkg/indexer/decode"
appBlobTypes "github.com/celestiaorg/celestia-app/x/blob/types"
"github.com/cosmos/cosmos-sdk/types"
"github.com/fatih/structs"
"github.com/shopspring/decimal"
"github.com/stretchr/testify/assert"
"testing"
)

// MsgPayForBlob
Expand Down Expand Up @@ -80,3 +81,74 @@ func TestDecodeMsg_SuccessOnPayForBlob(t *testing.T) {
assert.Equal(t, msgExpected, dm.Msg)
assert.Equal(t, addressesExpected, dm.Addresses)
}

func createMultipleMsgPayForBlob() types.Msg {
msgPayForBlob := appBlobTypes.MsgPayForBlobs{
Signer: "celestia1zefjxuq43xmjq9x4hhw23wkvvz6st5uhv40tys",
Namespaces: [][]byte{
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 189, 44, 204, 197, 144, 206, 197, 121, 37, 22},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 189, 44, 204, 197, 144, 206, 197, 121, 37, 22},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 189, 44, 204, 197, 144, 206, 197, 121, 37, 22},
},
BlobSizes: []uint32{1, 2, 3},
ShareCommitments: [][]byte{
{176, 28, 134, 119, 32, 117, 87, 107, 231, 67, 121, 255, 209, 106, 52, 99, 88, 183, 85, 36, 67, 137, 98, 199, 144, 159, 13, 178, 111, 190, 121, 36},
{176, 28, 134, 119, 32, 117, 87, 107, 231, 67, 121, 255, 209, 106, 52, 99, 88, 183, 85, 36, 67, 137, 98, 199, 144, 159, 13, 178, 111, 190, 121, 37},
{176, 28, 134, 119, 32, 117, 87, 107, 231, 67, 121, 255, 209, 106, 52, 99, 88, 183, 85, 36, 67, 137, 98, 199, 144, 159, 13, 178, 111, 190, 121, 38},
},
ShareVersions: []uint32{0, 0, 0},
}
return &msgPayForBlob
}

func TestDecodeMsg_ManyUpdatesInOnePayForBlob(t *testing.T) {
msgPayForBlob := createMultipleMsgPayForBlob()
blob, now := testsuite.EmptyBlock()
position := 0

dm, err := decode.Message(msgPayForBlob, blob.Height, blob.Block.Time, position, storageTypes.StatusSuccess)

addressesExpected := []storage.AddressWithType{
{
Type: storageTypes.MsgAddressTypeSigner,
Address: storage.Address{
Id: 0,
Height: blob.Height,
LastHeight: blob.Height,
Address: "celestia1zefjxuq43xmjq9x4hhw23wkvvz6st5uhv40tys",
Hash: []byte{0x16, 0x53, 0x23, 0x70, 0x15, 0x89, 0xb7, 0x20, 0x14, 0xd5, 0xbd, 0xdc, 0xa8, 0xba, 0xcc, 0x60, 0xb5, 0x5, 0xd3, 0x97},
Balance: storage.Balance{
Id: 0,
Total: decimal.Zero,
},
},
},
}

msgExpected := storage.Message{
Id: 0,
Height: blob.Height,
Time: now,
Position: 0,
Type: storageTypes.MsgPayForBlobs,
TxId: 0,
Data: structs.Map(msgPayForBlob),
Namespace: []storage.Namespace{
{
Id: 0,
FirstHeight: blob.Height,
Version: 0,
NamespaceID: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 189, 44, 204, 197, 144, 206, 197, 121, 37, 22},
Size: 6,
PfbCount: 1,
Reserved: false,
},
},
Addresses: addressesExpected,
}

assert.NoError(t, err)
assert.Equal(t, int64(6), dm.BlobsSize)
assert.Equal(t, msgExpected, dm.Msg)
assert.Equal(t, addressesExpected, dm.Addresses)
}
Loading