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

[WIP][IBC] Create the initial IBC module #795

Closed
wants to merge 71 commits into from
Closed
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
7560838
Update to use lazy loaded SMT
h5law May 24, 2023
6bfe4e1
Add SMT commits
h5law May 25, 2023
b9b2976
Merge branch 'main' into lazy_load_me
h5law May 26, 2023
f2dbe88
Initial IBC module declaration
h5law May 29, 2023
f8b729f
Begin to create stores and commitment proofs
h5law May 30, 2023
7562909
Add proof verification wrappers
h5law May 30, 2023
9f2c47c
Add new store creator
h5law May 30, 2023
80d3935
Add GetStoreKey function
h5law May 30, 2023
5ecc388
Add comment to key-value fields
h5law May 30, 2023
7632928
Reorder IBC errors
h5law May 30, 2023
31a4211
Consoslidate verification helper function
h5law May 30, 2023
674a965
Address linter errors
h5law May 30, 2023
5fc37c2
Add comments and tests tore generator
h5law May 30, 2023
f2311d5
Add path functions for keys as strings without store prefixes
h5law May 30, 2023
b439a14
Reformat comment
h5law May 30, 2023
8f8152c
Utilise commitment types
h5law May 30, 2023
ddb13bc
Return string from removePrefix
h5law May 30, 2023
6c97c46
Make updates atomic and revert on error
h5law May 30, 2023
4e8a569
Add populate store function
h5law May 30, 2023
8c8ffd4
Add new stores error
h5law May 30, 2023
abe94a4
Seperate store creation and initialisation fucntiosn to utils file
h5law May 30, 2023
2756aea
Add comments to struct methods
h5law May 30, 2023
51b45a9
Add initial store manager tests
h5law May 30, 2023
a7b0963
Add stop method to close db
h5law May 30, 2023
d72ca6d
Check returned store has same key
h5law May 30, 2023
f193c66
Add mocks folder
h5law May 31, 2023
b721b3a
Remove utils.go
h5law May 31, 2023
62da040
Seperate stores into seperate interfaces
h5law May 31, 2023
7a02e2a
Add more tests
h5law May 31, 2023
e0d371e
Update badger calls to use wrappers
h5law May 31, 2023
9a6adb7
Update to use smt v0.5.0 full release
h5law Jun 1, 2023
345a2f3
Add proof verification wrappers
h5law Jun 1, 2023
15a47ed
Revert "Update badger calls to use wrappers"
h5law Jun 1, 2023
b073087
Add discussion comment
h5law Jun 1, 2023
8bc5e1f
Remove old files and fix linter errors in kvstore
h5law Jun 1, 2023
37401eb
Simplify store creation and storemanager by using inherited interfaces
h5law Jun 1, 2023
59d7645
Address linter errors
h5law Jun 1, 2023
a27a992
update tests
h5law Jun 1, 2023
0535198
Add default id length, fix proof tests
h5law Jun 1, 2023
7a8b578
Merge branch 'main' into ibc/module_creation
h5law Jun 1, 2023
b5d7bd8
Add proof test suite
h5law Jun 1, 2023
3bac902
Integrate with cosmos/ics23
h5law Jun 2, 2023
0ca451f
Fix spelling mistake
h5law Jun 2, 2023
cedb466
Fix linter error
h5law Jun 2, 2023
1ab8cce
Add more test cases
h5law Jun 2, 2023
60ac2d8
Add GetTimestamp method
h5law Jun 2, 2023
6688341
Merge branch 'main' into ibc/module_creation
h5law Jun 2, 2023
c0cd1f0
Move tests
h5law Jun 2, 2023
facdf6a
Address linter errors
h5law Jun 2, 2023
f4d9c29
Fix non-membership validation
h5law Jun 2, 2023
a89b5dc
Add identifier and prefix tests
h5law Jun 2, 2023
74164b8
Add comments to non membership verification
h5law Jun 3, 2023
e0579bb
Add IBC module config and add to node startup
h5law Jun 4, 2023
5f452c2
Merge branch 'main' into ibc/module_creation
h5law Jun 4, 2023
c628399
Fix runtime config tests
h5law Jun 4, 2023
661cf57
Merge branch 'main' into ibc/module_creation
h5law Jun 10, 2023
db69a3a
Enforce interfaces consitent with codebase
h5law Jun 10, 2023
4d2b553
Address comments
h5law Jun 10, 2023
17e24d7
Rename store errors
h5law Jun 10, 2023
82539ec
Add clarifying comments
h5law Jun 10, 2023
1a5b2f1
Automatically add a host when the IBC module is enabled and the node …
h5law Jun 10, 2023
8f8bbf6
Fix tests
h5law Jun 10, 2023
bc68ce5
Fix linter error
h5law Jun 10, 2023
3bb7d4b
Add makefile test target and compare bytes directly in tests
h5law Jun 12, 2023
5bdbd90
Make commitmentprefix and commitmentpath local byte types
h5law Jun 13, 2023
da515af
Fix test
h5law Jun 13, 2023
cc3bf39
Begin ibc docs
h5law Jun 13, 2023
7e9a10f
Complete initial docs
h5law Jun 13, 2023
d1ff699
Fix doc links
h5law Jun 14, 2023
d0a10b1
Add comment to consensus e2e test ibc mock
h5law Jun 14, 2023
4550bea
Add commitment prefix introspection
h5law Jun 15, 2023
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
4 changes: 4 additions & 0 deletions build/config/config1.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@
"port": "50832",
"timeout": 30000,
"use_cors": false
},
"ibc": {
"host_enabled": true,
"stores_dir": "/var/ibc"
}
}
4 changes: 4 additions & 0 deletions build/config/config2.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@
"port": "50832",
"timeout": 30000,
"use_cors": false
},
"ibc": {
"host_enabled": true,
"stores_dir": "/var/ibc"
}
}
4 changes: 4 additions & 0 deletions build/config/config3.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@
"port": "50832",
"timeout": 30000,
"use_cors": false
},
"ibc": {
"host_enabled": true,
"stores_dir": "/var/ibc"
}
}
4 changes: 4 additions & 0 deletions build/config/config4.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@
"port": "50832",
"timeout": 30000,
"use_cors": false
},
"ibc": {
"host_enabled": true,
"stores_dir": "/var/ibc"
}
}
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (

require (
github.com/benbjohnson/clock v1.3.0
github.com/cosmos/ics23/go v0.10.0
github.com/deepmap/oapi-codegen v1.12.4
github.com/dgraph-io/badger/v3 v3.2103.2
github.com/foxcpp/go-mockdns v1.0.0
Expand Down Expand Up @@ -72,7 +73,7 @@ require (
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2 // indirect
github.com/opencontainers/runc v1.1.4 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.14.0
github.com/sirupsen/logrus v1.9.0 // indirect
go.opencensus.io v0.24.0 // indirect
Expand All @@ -87,6 +88,7 @@ require (
github.com/cockroachdb/apd/v3 v3.1.0 // indirect
github.com/containerd/cgroups v1.0.4 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cosmos/gogoproto v1.4.3 // indirect
github.com/cucumber/common/messages/go/v19 v19.1.2 // indirect
github.com/cucumber/gherkin/go/v26 v26.0.3 // indirect
github.com/cucumber/messages/go/v21 v21.0.1 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cosmos/gogoproto v1.4.3 h1:RP3yyVREh9snv/lsOvmsAPQt8f44LgL281X0IOIhhcI=
github.com/cosmos/gogoproto v1.4.3/go.mod h1:0hLIG5TR7IvV1fme1HCFKjfzW9X2x0Mo+RooWXCnOWU=
github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM=
github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
Expand Down
25 changes: 25 additions & 0 deletions ibc/host.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ibc

import (
"time"

"github.com/pokt-network/pocket/shared/modules"
)

var _ modules.IBCHost = (*Host)(nil)
h5law marked this conversation as resolved.
Show resolved Hide resolved

type Host struct {
h5law marked this conversation as resolved.
Show resolved Hide resolved
logger *modules.Logger

stores modules.StoreManager
}

// GetStoreManager returns the store manager for the host
func (h *Host) GetStoreManager() modules.StoreManager {
return h.stores
}

// GetTimestamp returns the current unix timestamp
func (h *Host) GetTimestamp() uint64 {
return uint64(time.Now().Unix())
}
100 changes: 100 additions & 0 deletions ibc/host/identifiers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package host

import (
"fmt"
"math/rand"
"strings"
"time"

coreTypes "github.com/pokt-network/pocket/shared/core/types"
)

const (
defaultIdentifierLength = 32
h5law marked this conversation as resolved.
Show resolved Hide resolved
identifierPrefix = "#"
identifierCharset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._+-#[]<>"
defaultMaxIdLength = 64
portMaxIdLength = 128
)

// basicValidation performs basic validation on the given identifier
func basicValidation(id string, minLength, maxLength int) error {
if strings.TrimSpace(id) == "" {
return coreTypes.ErrIBCInvalidID(id, "cannot be blank")
}

if len(id) < minLength || len(id) > maxLength {
return coreTypes.ErrIBCInvalidID(id, fmt.Sprintf("length must be between %d and %d", minLength, maxLength))
}

if !strings.HasPrefix(id, identifierPrefix) {
return coreTypes.ErrIBCInvalidID(id, fmt.Sprintf("must start with '%s'", identifierPrefix))
}

if strings.Contains(id, "/") {
h5law marked this conversation as resolved.
Show resolved Hide resolved
return coreTypes.ErrIBCInvalidID(id, "cannot contain '/'")
}

for _, c := range id {
if ok := strings.Contains(identifierCharset, string(c)); !ok {
return coreTypes.ErrIBCInvalidID(id, fmt.Sprintf("contains invalid character '%c'", c))
}
}

return nil
}

// ValidateClientID validates the client identifier string
func ValidateClientID(id string) error {
return basicValidation(id, 9, defaultMaxIdLength)
h5law marked this conversation as resolved.
Show resolved Hide resolved
}

// ValidateConnectionID validates the connection identifier string
func ValidateConnectionID(id string) error {
return basicValidation(id, 10, defaultMaxIdLength)
}

// ValidateChannelID validates the channel identifier string
func ValidateChannelID(id string) error {
return basicValidation(id, 8, defaultMaxIdLength)
}

// ValidatePortID validates the port identifier string
func ValidatePortID(id string) error {
return basicValidation(id, 2, portMaxIdLength)
}

// generateNewIdentifier generates a new identifier in the given range with the identifier prefix
func generateNewIdentifier(min, max int) string { //nolint:unparam // min is used although always the same
//nolint:gosec // weak random source okay - cryptographically secure randomness not required
r := rand.New(rand.NewSource(time.Now().UnixNano()))
size := r.Intn(max-1-min) + min // -1 for the prefix
h5law marked this conversation as resolved.
Show resolved Hide resolved

b := make([]byte, size)

for i := range b {
b[i] = identifierCharset[r.Intn(len(identifierCharset))]
}

return identifierPrefix + string(b)
}

// GenerateClientIdentifier generates a new client identifier
func GenerateClientIdentifier() string {
return generateNewIdentifier(defaultIdentifierLength, defaultMaxIdLength)
}

// GenerateConnectionIdentifier generates a new connection identifier
func GenerateConnectionIdentifier() string {
return generateNewIdentifier(defaultIdentifierLength, defaultMaxIdLength)
}

// GenerateChannelIdentifier generates a new channel identifier
func GenerateChannelIdentifier() string {
return generateNewIdentifier(defaultIdentifierLength, defaultMaxIdLength)
}

// GeneratePortIdentifier generates a new port identifier
func GeneratePortIdentifier() string {
return generateNewIdentifier(defaultIdentifierLength, portMaxIdLength)
}
Loading