-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IBC] Make the IBC Host a submodule with access to the bus (#868)
## Description <!-- reviewpad:summarize:start --> ### Summary generated by Reviewpad on 13 Jul 23 10:41 UTC This pull request includes several changes across multiple files. Here is a summary of the changes: 1. In the file `ibc/handle_message_test.go`, the file was renamed to `ibc/ibc_msg_mempool_test.go` with a similarity index of 85%. 2. In the same file, the imports were modified, and the `strings` package was added. 3. The test function `TestHandleMessage_ErrorAlreadyInMempool` was renamed to `TestEmitMessage_MessageAddedToLocalMempool`. Some code within the renamed test function was also modified, including changes in the preparation of test data and the addition of a transaction to the mempool. 4. The test function `TestHandleMessage_BasicValidation_Message` was renamed to `TestIBCMessage_BasicValidation_Message`. 5. The test function `TestHandleMessage_BasicValidation_Transaction` was renamed to `TestIBCMessage_BasicValidation_Transaction`. 6. A new test function `TestHandleMessage_ErrorAlreadyInMempool` was added to check for the error of having a duplicate transaction in the mempool. 7. A new test function `TestHandleMessage_ErrorAlreadyCommitted` was added to check for the error of having an already committed transaction. 8. The test function `TestHandleMessage_GetIndexedMessage` was modified to include changes in the preparation of the environment. 9. The test function `TestHandleMessage_AddToMempool` was removed. Additionally, other files such as `treestore_module.go`, `emitter.go`, `submodule.go`, `config.validator4.json`, `persistence/ibc.go`, `defaults.go`, `bus_module.go`, `ibc_store_module.go`, `bulk_store_cache.go`, `ibc_host_module.go`, `config.validator4.json`, `persistence/test/benchmark_state_test.go`, `p2p/README.md`, `runtime/manager_test.go`, `shared/node.go`, `persistence/test/manager_test.go`, `shared/modules/bulk_store_cache.go`, `ibc.go`, `shared/node.go`, `ics24.md`, `main_test.go` have also been modified. Please let me know if you need more information or details about any specific change. <!-- reviewpad:summarize:end --> ## Issue Fixes #854 ## Type of change Please mark the relevant option(s): - [x] New feature, functionality or library - [ ] Bug fix - [ ] Code health or cleanup - [ ] Major breaking change - [ ] Documentation - [ ] Other <!-- add details here if it a different type of change --> ## List of changes - Move IBC host into its own submodule - Enable local ProvableStore instances to emit events to alter the IBC state tree ## Testing - [x] `make develop_test`; if any code changes were made - [x] `make test_e2e` on [k8s LocalNet](https://github.com/pokt-network/pocket/blob/main/build/localnet/README.md); if any code changes were made - [x] `e2e-devnet-test` passes tests on [DevNet](https://pocketnetwork.notion.site/How-to-DevNet-ff1598f27efe44c09f34e2aa0051f0dd); if any code was changed - [x] [Docker Compose LocalNet](https://github.com/pokt-network/pocket/blob/main/docs/development/README.md); if any major functionality was changed or introduced - [x] [k8s LocalNet](https://github.com/pokt-network/pocket/blob/main/build/localnet/README.md); if any infrastructure or configuration changes were made ## Required Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have added, or updated, [`godoc` format comments](https://go.dev/blog/godoc) on touched members (see: [tip.golang.org/doc/comment](https://tip.golang.org/doc/comment)) - [x] I have tested my changes using the available tooling - [ ] I have updated the corresponding CHANGELOG ### If Applicable Checklist - [ ] I have updated the corresponding README(s); local and/or global - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] I have added, or updated, [mermaid.js](https://mermaid-js.github.io) diagrams in the corresponding README(s) - [ ] I have added, or updated, documentation and [mermaid.js](https://mermaid-js.github.io) diagrams in `shared/docs/*` if I updated `shared/*`README(s)
- Loading branch information
Showing
39 changed files
with
1,979 additions
and
676 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package host | ||
|
||
import ( | ||
"errors" | ||
"time" | ||
|
||
"github.com/pokt-network/pocket/ibc/store" | ||
"github.com/pokt-network/pocket/runtime/configs" | ||
coreTypes "github.com/pokt-network/pocket/shared/core/types" | ||
"github.com/pokt-network/pocket/shared/modules" | ||
"github.com/pokt-network/pocket/shared/modules/base_modules" | ||
) | ||
|
||
var _ modules.IBCHostSubmodule = &ibcHost{} | ||
|
||
type ibcHost struct { | ||
base_modules.IntegrableModule | ||
|
||
cfg *configs.IBCHostConfig | ||
logger *modules.Logger | ||
storesDir string | ||
} | ||
|
||
func Create(bus modules.Bus, config *configs.IBCHostConfig, options ...modules.IBCHostOption) (modules.IBCHostSubmodule, error) { | ||
return new(ibcHost).Create(bus, config, options...) | ||
} | ||
|
||
// WithLogger assigns a logger for the IBC host | ||
func WithLogger(logger *modules.Logger) modules.IBCHostOption { | ||
return func(m modules.IBCHostSubmodule) { | ||
if mod, ok := m.(*ibcHost); ok { | ||
mod.logger = logger | ||
} | ||
} | ||
} | ||
|
||
// WithStoresDir assigns a stores directory for the IBC host | ||
func WithStoresDir(dir string) modules.IBCHostOption { | ||
return func(m modules.IBCHostSubmodule) { | ||
if mod, ok := m.(*ibcHost); ok { | ||
mod.storesDir = dir | ||
} | ||
} | ||
} | ||
|
||
func (*ibcHost) Create(bus modules.Bus, config *configs.IBCHostConfig, options ...modules.IBCHostOption) (modules.IBCHostSubmodule, error) { | ||
h := &ibcHost{ | ||
cfg: config, | ||
} | ||
for _, option := range options { | ||
option(h) | ||
} | ||
h.logger.Info().Msg("🛰️ Creating IBC host 🛰️") | ||
bus.RegisterModule(h) | ||
_, err := store.Create(h.GetBus(), | ||
h.cfg.BulkStoreCacher, | ||
store.WithLogger(h.logger), | ||
store.WithStoresDir(h.storesDir), | ||
store.WithPrivateKey(h.cfg.PrivateKey), | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return h, nil | ||
} | ||
|
||
func (h *ibcHost) GetModuleName() string { return modules.IBCHostSubmoduleName } | ||
|
||
// GetTimestamp returns the current unix timestamp | ||
func (h *ibcHost) GetTimestamp() uint64 { | ||
return uint64(time.Now().Unix()) | ||
} | ||
|
||
// GetProvableStore returns an instance of a provable store with the given name with the | ||
// CommitmentPrefix set to []byte(name). The store is created if it does not exist. | ||
// | ||
// Any changes made using the store are handled locally and propagated through the bus, | ||
// added to all nodes' mempools ready for inclusion in the next block to transition the IBC store state tree. | ||
// Any operations will ensure the CommitmentPrefix is prepended to the key if not present already. | ||
func (h *ibcHost) GetProvableStore(name string) (modules.ProvableStore, error) { | ||
if err := h.GetBus().GetBulkStoreCacher().AddStore(name); err != nil && !errors.Is(err, coreTypes.ErrIBCStoreAlreadyExists(name)) { | ||
return nil, err | ||
} | ||
return h.GetBus().GetBulkStoreCacher().GetStore(name) | ||
} |
Oops, something went wrong.