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

Opt/remove init option #5974

Merged
merged 3 commits into from
May 19, 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
23 changes: 1 addition & 22 deletions app/node/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"

"github.com/filecoin-project/venus/pkg/repo/fskeystore"
"github.com/filecoin-project/venus/pkg/wallet/key"

cbor "github.com/ipfs/go-ipld-cbor"
acrypto "github.com/libp2p/go-libp2p/core/crypto"
Expand All @@ -18,31 +17,11 @@ const defaultPeerKeyBits = 2048

const peerPrivateKey = "self"

// initCfg contains configuration for initializing a node's repo.
type initCfg struct {
initImports []*key.KeyInfo
}

// InitOpt is an option for initialization of a node's repo.
type InitOpt func(*initCfg)

// ImportKeyOpt imports the provided key during initialization.
func ImportKeyOpt(ki *key.KeyInfo) InitOpt {
return func(opts *initCfg) {
opts.initImports = append(opts.initImports, ki)
}
}

// Init initializes a Filecoin repo with genesis state and keys.
// This will always set the configuration for wallet default address (to the specified default
// key or a newly generated one), but otherwise leave the repo's config object intact.
// Make further configuration changes after initialization.
func Init(ctx context.Context, r repo.Repo, gen genesis.InitFunc, opts ...InitOpt) error {
cfg := new(initCfg)
for _, o := range opts {
o(cfg)
}

func Init(ctx context.Context, r repo.Repo, gen genesis.InitFunc) error {
bs := r.Datastore()
cst := cbor.NewCborStore(bs)
_, err := genesis.Init(ctx, r, bs, cst, gen)
Expand Down
13 changes: 2 additions & 11 deletions app/node/test/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
type NodeBuilder struct {
// Initialisation function for the genesis block and state.
gif genesis.InitFunc
// Options to the repo initialisation.
initOpts []node.InitOpt
// Mutations to be applied to node config after initialisation.
configMutations []node.ConfigOpt
// Mutations to be applied to the node builder config before building.
Expand All @@ -35,8 +33,7 @@ type NodeBuilder struct {
// NewNodeBuilder creates a new node builder.
func NewNodeBuilder(tb testing.TB) *NodeBuilder {
return &NodeBuilder{
gif: gengen.MakeGenesisFunc(gengen.NetworkName("gfctest")),
initOpts: []node.InitOpt{},
gif: gengen.MakeGenesisFunc(gengen.NetworkName("gfctest")),
configMutations: []node.ConfigOpt{
// Default configurations that make sense for integration tests.
// The can be overridden by subsequent `withConfigChanges`.
Expand All @@ -62,12 +59,6 @@ func (b *NodeBuilder) WithGenesisInit(gif genesis.InitFunc) *NodeBuilder {
return b
}

// WithInitOpt adds one or more options to repo initialisation.
func (b *NodeBuilder) WithInitOpt(opts ...node.InitOpt) *NodeBuilder {
b.initOpts = append(b.initOpts, opts...)
return b
}

// WithBuilderOpt adds one or more node building options to node creation.
func (b *NodeBuilder) WithBuilderOpt(opts ...node.BuilderOpt) *NodeBuilder {
b.builderOpts = append(b.builderOpts, opts...)
Expand All @@ -89,7 +80,7 @@ func (b *NodeBuilder) Build(ctx context.Context) *node.Node {
for _, opt := range b.configMutations {
opt(repo.Config())
}
b.requireNoError(node.Init(ctx, repo, b.gif, b.initOpts...))
b.requireNoError(node.Init(ctx, repo, b.gif))

// Initialize the node.
repoConfigOpts, err := node.OptionsFromRepo(repo)
Expand Down
7 changes: 0 additions & 7 deletions app/node/test/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,6 @@ func (cs *ChainSeed) Addr(t *testing.T, key int) address.Address {
return a
}

// KeyInitOpt is a node init option that imports one of the chain seed's
// keys to a node's wallet
func (cs *ChainSeed) KeyInitOpt(which int) node.InitOpt {
kinfo := cs.info.Keys[which]
return node.ImportKeyOpt(kinfo)
}

// FixtureChainSeed returns the genesis function that
func FixtureChainSeed(t *testing.T) *ChainSeed {
return MakeChainSeed(t, &fortest.TestGenGenConfig)
Expand Down
4 changes: 2 additions & 2 deletions app/submodule/network/network_submodule.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"github.com/filecoin-project/venus/pkg/net/helloprotocol"

"github.com/dchest/blake2b"
"github.com/ipfs/go-bitswap"
bsnet "github.com/ipfs/go-bitswap/network"
bserv "github.com/ipfs/go-blockservice"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-datastore"
Expand All @@ -22,6 +20,7 @@ import (
"github.com/ipfs/go-graphsync/storeutil"
exchange "github.com/ipfs/go-ipfs-exchange-interface"
cbor "github.com/ipfs/go-ipld-cbor"
bsnet "github.com/ipfs/go-libipfs/bitswap/network"
blocks "github.com/ipfs/go-libipfs/blocks"
logging "github.com/ipfs/go-log"
"github.com/libp2p/go-libp2p"
Expand All @@ -41,6 +40,7 @@ import (
dtimpl "github.com/filecoin-project/go-data-transfer/impl"
dtnet "github.com/filecoin-project/go-data-transfer/network"
dtgstransport "github.com/filecoin-project/go-data-transfer/transport/graphsync"
"github.com/ipfs/go-libipfs/bitswap"

"github.com/filecoin-project/venus/pkg/chain"
"github.com/filecoin-project/venus/pkg/config"
Expand Down
2 changes: 0 additions & 2 deletions cmd/message_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ func TestMessageSend(t *testing.T) {
cs := test.FixtureChainSeed(t)
builder.WithGenesisInit(cs.GenesisInitFunc)
builder.WithConfig(test.DefaultAddressConfigOpt(defaultAddr))
builder.WithInitOpt(cs.KeyInitOpt(1))
builder.WithInitOpt(cs.KeyInitOpt(0))

n, cmdClient, done := builder.BuildAndStartAPI(ctx)
defer done()
Expand Down
19 changes: 8 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ require (
github.com/hashicorp/golang-lru/v2 v2.0.2
github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c
github.com/ipfs-force-community/metrics v1.0.1-0.20211022060227-11142a08b729
github.com/ipfs/go-bitswap v0.10.2
github.com/ipfs/go-blockservice v0.4.0
github.com/ipfs/go-cid v0.3.2
github.com/ipfs/go-datastore v0.6.0
Expand Down Expand Up @@ -118,16 +117,6 @@ require (
gotest.tools v2.2.0+incompatible
)

require (
github.com/bytedance/sonic v1.8.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/goccy/go-json v0.10.0 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/ipfs/go-block-format v0.1.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
)

require (
github.com/BurntSushi/toml v1.1.0
github.com/Kubuxu/go-os-helper v0.0.1 // indirect
Expand All @@ -137,8 +126,10 @@ require (
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bep/debounce v1.2.1 // indirect
github.com/bytedance/sonic v1.8.0 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/containerd/cgroups v1.0.4 // indirect
github.com/coreos/go-systemd/v22 v22.4.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
Expand Down Expand Up @@ -181,6 +172,7 @@ require (
github.com/go-resty/resty/v2 v2.4.0 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/goccy/go-json v0.10.0 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand All @@ -193,12 +185,15 @@ require (
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/hannahhoward/cbor-gen-for v0.0.0-20200817222906-ea96cece81f1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/huin/goupnp v1.0.3 // indirect
github.com/influxdata/influxdb-client-go/v2 v2.2.2 // indirect
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 // indirect
github.com/ipfs/bbloom v0.0.4 // indirect
github.com/ipfs/go-bitfield v1.1.0 // indirect
github.com/ipfs/go-bitswap v0.12.0 // indirect
github.com/ipfs/go-block-format v0.1.1 // indirect
github.com/ipfs/go-ipfs-delay v0.0.1 // indirect
github.com/ipfs/go-ipfs-posinfo v0.0.1 // indirect
github.com/ipfs/go-ipfs-pq v0.0.3 // indirect
Expand Down Expand Up @@ -292,6 +287,7 @@ require (
github.com/stretchr/objx v0.5.0 // indirect
github.com/subosito/gotenv v1.4.0 // indirect
github.com/texttheater/golang-levenshtein v0.0.0-20180516184445-d188e65d659e // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/uber/jaeger-client-go v2.25.0+incompatible // indirect
github.com/ugorji/go/codec v1.2.9 // indirect
github.com/urfave/cli/v2 v2.16.3 // indirect
Expand All @@ -306,6 +302,7 @@ require (
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go4.org v0.0.0-20200411211856-f5505b9728dd // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
golang.org/x/exp v0.0.0-20220916125017-b168a2c6b86b // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/term v0.5.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -695,8 +695,8 @@ github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL
github.com/ipfs/go-bitswap v0.1.0/go.mod h1:FFJEf18E9izuCqUtHxbWEvq+reg7o4CW5wSAE1wsxj0=
github.com/ipfs/go-bitswap v0.1.2/go.mod h1:qxSWS4NXGs7jQ6zQvoPY3+NmOfHHG47mhkiLzBpJQIs=
github.com/ipfs/go-bitswap v0.5.1/go.mod h1:P+ckC87ri1xFLvk74NlXdP0Kj9RmWAh4+H78sC6Qopo=
github.com/ipfs/go-bitswap v0.10.2 h1:B81RIwkTnIvSYT1ZCzxjYTeF0Ek88xa9r1AMpTfk+9Q=
github.com/ipfs/go-bitswap v0.10.2/go.mod h1:+fZEvycxviZ7c+5KlKwTzLm0M28g2ukCPqiuLfJk4KA=
github.com/ipfs/go-bitswap v0.12.0 h1:ClbLaufwv8SRQK0sBhl4wDVqJoZGAGMVxdjQy5CTt6c=
github.com/ipfs/go-bitswap v0.12.0/go.mod h1:Iwjkd6+vaDjVIa6b6ogmZgs+b5U3EkIFEX79kQ4DjnI=
github.com/ipfs/go-block-format v0.0.1/go.mod h1:DK/YYcsSUIVAFNwo/KZCdIIbpN0ROH/baNLgayt4pFc=
github.com/ipfs/go-block-format v0.0.2/go.mod h1:AWR46JfpcObNfg3ok2JHDUfdiHRgWhJgCQF+KIgOPJY=
github.com/ipfs/go-block-format v0.0.3/go.mod h1:4LmD4ZUw0mhO+JSKdpWwrzATiEfM7WWgQ8H5l6P8MVk=
Expand Down
2 changes: 1 addition & 1 deletion venus-devtool/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbG
github.com/ipfs/go-bitswap v0.1.0/go.mod h1:FFJEf18E9izuCqUtHxbWEvq+reg7o4CW5wSAE1wsxj0=
github.com/ipfs/go-bitswap v0.1.2/go.mod h1:qxSWS4NXGs7jQ6zQvoPY3+NmOfHHG47mhkiLzBpJQIs=
github.com/ipfs/go-bitswap v0.5.1/go.mod h1:P+ckC87ri1xFLvk74NlXdP0Kj9RmWAh4+H78sC6Qopo=
github.com/ipfs/go-bitswap v0.10.2 h1:B81RIwkTnIvSYT1ZCzxjYTeF0Ek88xa9r1AMpTfk+9Q=
github.com/ipfs/go-bitswap v0.12.0 h1:ClbLaufwv8SRQK0sBhl4wDVqJoZGAGMVxdjQy5CTt6c=
github.com/ipfs/go-block-format v0.0.1/go.mod h1:DK/YYcsSUIVAFNwo/KZCdIIbpN0ROH/baNLgayt4pFc=
github.com/ipfs/go-block-format v0.0.2/go.mod h1:AWR46JfpcObNfg3ok2JHDUfdiHRgWhJgCQF+KIgOPJY=
github.com/ipfs/go-block-format v0.0.3/go.mod h1:4LmD4ZUw0mhO+JSKdpWwrzATiEfM7WWgQ8H5l6P8MVk=
Expand Down