From 3db9c566976aa336e42b7deedb4a03ffad1a01e1 Mon Sep 17 00:00:00 2001 From: Cosmos SDK <113218068+github-prbot@users.noreply.github.com> Date: Mon, 9 Sep 2024 15:33:12 +0200 Subject: [PATCH] chore: fix spelling errors (#21610) Co-authored-by: github-merge-queue <118344674+github-merge-queue@users.noreply.github.com> (cherry picked from commit 50288938d1b625a19615db81a062a5259aaaba8c) # Conflicts: # schema/appdata/data.go --- schema/appdata/data.go | 138 ++++++++++++++++++ server/v2/cometbft/abci_test.go | 4 +- .../v2/cometbft/internal/mock/mock_store.go | 16 +- 3 files changed, 148 insertions(+), 10 deletions(-) create mode 100644 schema/appdata/data.go diff --git a/schema/appdata/data.go b/schema/appdata/data.go new file mode 100644 index 000000000000..ef54fd2553ae --- /dev/null +++ b/schema/appdata/data.go @@ -0,0 +1,138 @@ +package appdata + +import ( + "encoding/json" + + "cosmossdk.io/schema" +) + +// ModuleInitializationData represents data for related to module initialization, in particular +// the module's schema. +type ModuleInitializationData struct { + // ModuleName is the name of the module. + ModuleName string + + // Schema is the schema of the module. + Schema schema.ModuleSchema +} + +// StartBlockData represents the data that is passed to a listener when a block is started. +type StartBlockData struct { + // Height is the height of the block. + Height uint64 + + // Bytes is the raw byte representation of the block header. It may be nil if the source does not provide it. + HeaderBytes ToBytes + + // JSON is the JSON representation of the block header. It should generally be a JSON object. + // It may be nil if the source does not provide it. + HeaderJSON ToJSON +} + +// TxData represents the raw transaction data that is passed to a listener. +type TxData struct { + // TxIndex is the index of the transaction in the block. + TxIndex int32 + + // Bytes is the raw byte representation of the transaction. + Bytes ToBytes + + // JSON is the JSON representation of the transaction. It should generally be a JSON object. + JSON ToJSON +} + +// EventData represents event data that is passed to a listener when events are received. +type EventData struct { + // Events are the events that are received. + Events []Event +} + +// Event represents the data for a single event. +type Event struct { + // BlockStage represents the stage of the block at which this event is associated. + // If the block stage is unknown, it should be set to UnknownBlockStage. + BlockStage BlockStage + + // TxIndex is the 1-based index of the transaction in the block to which this event is associated. + // If TxIndex is zero, it means that we do not know the transaction index. + // Otherwise, the index should start with 1. + TxIndex int32 + + // MsgIndex is the 1-based index of the message in the transaction to which this event is associated. + // If MsgIndex is zero, it means that we do not know the message index. + // Otherwise, the index should start with 1. + MsgIndex int32 + + // EventIndex is the 1-based index of the event in the message to which this event is associated. + // If EventIndex is zero, it means that we do not know the event index. + // Otherwise, the index should start with 1. + EventIndex int32 + + // Type is the type of the event. + Type string + + // Data lazily returns the JSON representation of the event. + Data ToJSON + + // Attributes lazily returns the key-value attribute representation of the event. + Attributes ToEventAttributes +} + +// BlockStage represents the stage of block processing for an event. +type BlockStage int32 + +const ( + // UnknownBlockStage indicates that we do not know the block stage. + UnknownBlockStage BlockStage = iota + + // PreBlockStage indicates that the event is associated with the pre-block stage. + PreBlockStage + + // BeginBlockStage indicates that the event is associated with the begin-block stage. + BeginBlockStage + + // TxProcessingStage indicates that the event is associated with the transaction processing stage. + TxProcessingStage + + // EndBlockStage indicates that the event is associated with the end-block stage. + EndBlockStage +) + +type EventAttribute = struct { + Key, Value string +} + +// ToBytes is a function that lazily returns the raw byte representation of data. +type ToBytes = func() ([]byte, error) + +// ToJSON is a function that lazily returns the JSON representation of data. +type ToJSON = func() (json.RawMessage, error) + +// ToEventAttributes is a function that lazily returns the key-value attribute representation of an event. +type ToEventAttributes = func() ([]EventAttribute, error) + +// KVPairData represents a batch of key-value pair data that is passed to a listener. +type KVPairData struct { + Updates []ActorKVPairUpdate +} + +// ActorKVPairUpdate represents a key-value pair update for a specific module or account. +type ActorKVPairUpdate = struct { + // Actor is the byte representation of the module or account that is updating the key-value pair. + Actor []byte + + // StateChanges are key-value pair updates. + StateChanges []schema.KVPairUpdate +} + +// ObjectUpdateData represents object update data that is passed to a listener. +type ObjectUpdateData struct { + // ModuleName is the name of the module that the update corresponds to. + ModuleName string + + // Updates are the object updates. + Updates []schema.ObjectUpdate +} + +// CommitData represents commit data. It is empty for now, but fields could be added later. +type CommitData struct{} diff --git a/server/v2/cometbft/abci_test.go b/server/v2/cometbft/abci_test.go index 2208894e3878..64b321630cc0 100644 --- a/server/v2/cometbft/abci_test.go +++ b/server/v2/cometbft/abci_test.go @@ -448,7 +448,7 @@ func TestConsensus_PrepareProposal_With_Handler_NoOpMempool(t *testing.T) { require.NoError(t, err) require.Equal(t, len(res.Txs), 0) - // have tx exeed MaxTxBytes + // have tx exceed MaxTxBytes // each mock tx has 128 bytes, should select 2 txs res, err = c.PrepareProposal(context.Background(), &abciproto.PrepareProposalRequest{ Height: 1, @@ -525,7 +525,7 @@ func TestConsensus_ProcessProposal_With_Handler(t *testing.T) { c.processProposalHandler = handlers.NewDefaultProposalHandler(c.mempool).ProcessHandler() - // exeed max gas + // exceed max gas res, err := c.ProcessProposal(context.Background(), &abciproto.ProcessProposalRequest{ Height: 1, Txs: [][]byte{mockTx.Bytes(), mockTx.Bytes(), mockTx.Bytes(), mockTx.Bytes()}, diff --git a/server/v2/cometbft/internal/mock/mock_store.go b/server/v2/cometbft/internal/mock/mock_store.go index ee9089f8d49f..dee4d8baf915 100644 --- a/server/v2/cometbft/internal/mock/mock_store.go +++ b/server/v2/cometbft/internal/mock/mock_store.go @@ -18,7 +18,7 @@ import ( type MockStore struct { Storage storev2.VersionedDatabase - Commiter storev2.Committer + Committer storev2.Committer } func NewMockStorage(logger log.Logger, dir string) storev2.VersionedDatabase { @@ -38,7 +38,7 @@ func NewMockCommiter(logger log.Logger, actors ...string) storev2.Committer { } func NewMockStore(ss storev2.VersionedDatabase, sc storev2.Committer) *MockStore { - return &MockStore{Storage: ss, Commiter: sc} + return &MockStore{Storage: ss, Committer: sc} } func (s *MockStore) GetLatestVersion() (uint64, error) { @@ -66,18 +66,18 @@ func (s *MockStore) Commit(changeset *corestore.Changeset) (corestore.Hash, erro return []byte{}, err } - err = s.Commiter.WriteChangeset(changeset) + err = s.Committer.WriteChangeset(changeset) if err != nil { return []byte{}, err } - commitInfo, err := s.Commiter.Commit(v + 1) + commitInfo, err := s.Committer.Commit(v + 1) fmt.Println("commitInfo", commitInfo, err) return []byte{}, err } func (s *MockStore) StateAt(version uint64) (corestore.ReaderMap, error) { - info, err := s.Commiter.GetCommitInfo(version) + info, err := s.Committer.GetCommitInfo(version) if err != nil || info == nil { return nil, fmt.Errorf("failed to get commit info for version %d: %w", version, err) } @@ -89,7 +89,7 @@ func (s *MockStore) GetStateStorage() storev2.VersionedDatabase { } func (s *MockStore) GetStateCommitment() storev2.Committer { - return s.Commiter + return s.Committer } type Result struct { @@ -121,7 +121,7 @@ func (s *MockStore) LastCommitID() (proof.CommitID, error) { } func (s *MockStore) SetInitialVersion(v uint64) error { - return s.Commiter.SetInitialVersion(v) + return s.Committer.SetInitialVersion(v) } func (s *MockStore) WorkingHash(changeset *corestore.Changeset) (corestore.Hash, error) { @@ -131,7 +131,7 @@ func (s *MockStore) WorkingHash(changeset *corestore.Changeset) (corestore.Hash, return []byte{}, err } - err = s.Commiter.WriteChangeset(changeset) + err = s.Committer.WriteChangeset(changeset) if err != nil { return []byte{}, err }