Skip to content

Commit

Permalink
fix(nodebuilder/das): Skip config validation for bridge node (#1373)
Browse files Browse the repository at this point in the history
Related to #1372

Co-authored-by: Ryan <ryanford@poluglottos.com>
  • Loading branch information
renaynay and distractedm1nd committed Nov 25, 2022
1 parent 7df5cf8 commit 0849c19
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 24 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ replace github.com/ipfs/go-verifcid => github.com/celestiaorg/go-verifcid v0.0.1

require (
cosmossdk.io/math v1.0.0-beta.3
github.com/BurntSushi/toml v1.2.0
github.com/BurntSushi/toml v1.2.1
github.com/alecthomas/jsonschema v0.0.0-20200530073317-71f438968921
github.com/celestiaorg/celestia-app v0.10.0-rc1
github.com/celestiaorg/go-libp2p-messenger v0.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3/go.mod h1:KLF4gFr6DcKFZwSu
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0/go.mod h1:tPaiy8S5bQ+S5sOiDlINkp7+Ef339+Nz5L5XO+cnOHo=
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQcITbvhmL4+C4cKA87NW0tfm3Kl9VXRoPywFg=
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4=
Expand Down
28 changes: 16 additions & 12 deletions nodebuilder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,28 @@ type Config struct {
Gateway gateway.Config
Share share.Config
Header header.Config
DASer das.Config
DASer das.Config `toml:",omitempty"`
}

// DefaultConfig provides a default Config for a given Node Type 'tp'.
// NOTE: Currently, configs are identical, but this will change.
func DefaultConfig(tp node.Type) *Config {
commonConfig := &Config{
Core: core.DefaultConfig(),
State: state.DefaultConfig(),
P2P: p2p.DefaultConfig(),
RPC: rpc.DefaultConfig(),
Gateway: gateway.DefaultConfig(),
Share: share.DefaultConfig(),
Header: header.DefaultConfig(),
}

switch tp {
case node.Bridge, node.Light, node.Full:
return &Config{
Core: core.DefaultConfig(),
State: state.DefaultConfig(),
P2P: p2p.DefaultConfig(),
RPC: rpc.DefaultConfig(),
Gateway: gateway.DefaultConfig(),
Share: share.DefaultConfig(),
Header: header.DefaultConfig(),
DASer: das.DefaultConfig(),
}
case node.Bridge:
return commonConfig
case node.Light, node.Full:
commonConfig.DASer = das.DefaultConfig()
return commonConfig
default:
panic("node: invalid node type")
}
Expand Down
27 changes: 19 additions & 8 deletions nodebuilder/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,26 @@ import (
"github.com/celestiaorg/celestia-node/nodebuilder/node"
)

// TestConfigWriteRead tests that the configs for all node types can be encoded to and from TOML.
func TestConfigWriteRead(t *testing.T) {
buf := bytes.NewBuffer(nil)
in := DefaultConfig(node.Bridge)
tests := []node.Type{
node.Full,
node.Light,
node.Bridge,
}

err := in.Encode(buf)
require.NoError(t, err)
for _, tp := range tests {
t.Run(tp.String(), func(t *testing.T) {
buf := bytes.NewBuffer(nil)
in := DefaultConfig(tp)

var out Config
err = out.Decode(buf)
require.NoError(t, err)
assert.EqualValues(t, in, &out)
err := in.Encode(buf)
require.NoError(t, err)

var out Config
err = out.Decode(buf)
require.NoError(t, err)
assert.EqualValues(t, in, &out)
})
}
}
7 changes: 6 additions & 1 deletion nodebuilder/das/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import (
)

func ConstructModule(tp node.Type, cfg *Config) fx.Option {
err := cfg.Validate()
var err error
// do not validate daser config for bridge node as it
// does not need it
if tp != node.Bridge {
err = cfg.Validate()
}

baseComponents := fx.Options(
fx.Supply(*cfg),
Expand Down

0 comments on commit 0849c19

Please sign in to comment.