Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
e7e6169
Create options package
islamaliev Jan 7, 2026
4b6ea6c
Migrate to new options
islamaliev Jan 7, 2026
9a15c54
Retrieve identity from options
islamaliev Jan 7, 2026
e0bddbc
Pass ctx to checkNodeAccess explicitly
islamaliev Jan 7, 2026
b60f5c2
User options
islamaliev Jan 8, 2026
997605f
Pass more identities explicitly
islamaliev Jan 8, 2026
5af9e13
Add util method
islamaliev Jan 8, 2026
53c0425
Handle the rest of identities in cbindings
islamaliev Jan 8, 2026
c3ec1a0
Polish
islamaliev Jan 8, 2026
e2bf803
Pass identity with options in tests
islamaliev Jan 8, 2026
e5d68f9
More cases
islamaliev Jan 9, 2026
ba930f2
Merge from develop
islamaliev Jan 9, 2026
ad1f64c
Fix signature verification
islamaliev Jan 12, 2026
780c89e
Pass identity in context
islamaliev Jan 12, 2026
db61ac4
Add dedicated options
islamaliev Jan 12, 2026
c0a484f
Polish
islamaliev Jan 12, 2026
a72544d
Revert
islamaliev Jan 12, 2026
4bedb65
Introduce node options
islamaliev Jan 12, 2026
f982889
Fix lint
islamaliev Jan 12, 2026
24cd930
Merge remote-tracking branch 'upstream/develop' into feat/make-identi…
islamaliev Jan 12, 2026
18859b9
Merge remote-tracking branch 'upstream/develop' into feat/make-identi…
islamaliev Jan 19, 2026
93c6994
Adjust after merge
islamaliev Jan 19, 2026
3cefc0b
Merge remote-tracking branch 'upstream/develop' into feat/make-identi…
islamaliev Jan 23, 2026
687750d
Rename
islamaliev Jan 23, 2026
69e19ab
Add missing identities
islamaliev Jan 23, 2026
98553b4
Merge remote-tracking branch 'upstream/develop' into feat/consolidate…
islamaliev Feb 11, 2026
a830df1
Adjust node options
islamaliev Feb 11, 2026
00d4ca7
Fix JS
islamaliev Feb 11, 2026
9809f3f
Fix lint
islamaliev Feb 11, 2026
749b1d7
Refactor
islamaliev Feb 12, 2026
07a799e
Refactor
islamaliev Feb 12, 2026
7536179
Refactor
islamaliev Feb 12, 2026
0cf2853
Refactor
islamaliev Feb 12, 2026
2996cff
Refactor internal options
islamaliev Feb 12, 2026
83a974e
Remove unrelated code
islamaliev Feb 13, 2026
a80e0dc
Polish
islamaliev Feb 13, 2026
4ee40e3
Merge remote-tracking branch 'upstream/develop' into feat/consolidate…
islamaliev Feb 13, 2026
2bf1c56
Format
islamaliev Feb 13, 2026
876333a
Update docs
islamaliev Feb 13, 2026
a382165
Fix
islamaliev Feb 13, 2026
0512714
Merge remote-tracking branch 'upstream/develop' into feat/consolidate…
islamaliev Feb 13, 2026
d0bafe8
Panic if navigation without constructor
islamaliev Feb 13, 2026
82ad540
Set properly pubsub p2p option
islamaliev Feb 13, 2026
df9e9fa
Add constructors
islamaliev Feb 13, 2026
18c1918
Fix p2p test config
islamaliev Feb 13, 2026
069f007
Merge remote-tracking branch 'upstream/develop' into feat/consolidate…
islamaliev Feb 13, 2026
6e4b95f
Store p2p opts in test state
islamaliev Feb 13, 2026
a840d29
Polish
islamaliev Feb 13, 2026
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
34 changes: 15 additions & 19 deletions cbindings/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
"strconv"
"time"

"github.com/sourcenetwork/go-p2p"

"github.com/sourcenetwork/defradb/internal/db"
"github.com/sourcenetwork/defradb/client/options"
"github.com/sourcenetwork/defradb/node"
)

Expand All @@ -40,42 +38,40 @@

ctx := context.Background()

opts := []node.Option{
db.WithLensRuntime(db.Wazero),
}
opts := options.Node()
opts.DB().SetLensRuntime(options.NodeWASMLensRuntime)

Check warning on line 42 in cbindings/node.go

View check run for this annotation

Codecov / codecov/patch

cbindings/node.go#L41-L42

Added lines #L41 - L42 were not covered by tests

if gocOptions.DbPath != "" {
opts = append(opts, node.WithStorePath(gocOptions.DbPath))
opts.Store().SetPath(gocOptions.DbPath)

Check warning on line 45 in cbindings/node.go

View check run for this annotation

Codecov / codecov/patch

cbindings/node.go#L45

Added line #L45 was not covered by tests
}
if len(listeningAddresses) > 0 {
opts = append(opts, p2p.WithListenAddresses(listeningAddresses...))
opts.P2P().SetListenAddresses(listeningAddresses...)

Check warning on line 48 in cbindings/node.go

View check run for this annotation

Codecov / codecov/patch

cbindings/node.go#L48

Added line #L48 was not covered by tests
}
maxTxnRetries := gocOptions.MaxTransactionRetries
if maxTxnRetries > 0 {
opts = append(opts, db.WithMaxRetries(maxTxnRetries))
opts.DB().SetMaxTxnRetries(maxTxnRetries)

Check warning on line 52 in cbindings/node.go

View check run for this annotation

Codecov / codecov/patch

cbindings/node.go#L52

Added line #L52 was not covered by tests
}
disableP2PFlag := gocOptions.DisableP2P != 0
if disableP2PFlag {
opts = append(opts, node.WithDisableP2P(true))
opts.SetDisableP2P(true)

Check warning on line 56 in cbindings/node.go

View check run for this annotation

Codecov / codecov/patch

cbindings/node.go#L56

Added line #L56 was not covered by tests
}
disableAPIFlag := gocOptions.DisableAPI != 0
if disableAPIFlag {
opts = append(opts, node.WithDisableAPI(true))
opts.SetDisableAPI(true)

Check warning on line 60 in cbindings/node.go

View check run for this annotation

Codecov / codecov/patch

cbindings/node.go#L60

Added line #L60 was not covered by tests
}
if inMemoryFlag {
opts = append(opts, node.WithBadgerInMemory(true))
opts.Store().SetBadgerInMemory(true)

Check warning on line 63 in cbindings/node.go

View check run for this annotation

Codecov / codecov/patch

cbindings/node.go#L63

Added line #L63 was not covered by tests
}
peers := splitCommaSeparatedString(gocOptions.Peers)
if len(peers) > 0 {
opts = append(opts, p2p.WithBootstrapPeers(peers...))
opts.P2P().SetBootstrapPeers(peers...)

Check warning on line 67 in cbindings/node.go

View check run for this annotation

Codecov / codecov/patch

cbindings/node.go#L67

Added line #L67 was not covered by tests
}
if gocOptions.Identity != nil {
opts = append(opts, db.WithNodeIdentity(gocOptions.Identity))
opts.DB().SetNodeIdentity(gocOptions.Identity)

Check warning on line 70 in cbindings/node.go

View check run for this annotation

Codecov / codecov/patch

cbindings/node.go#L70

Added line #L70 was not covered by tests
}
if gocOptions.EnableNodeACP != 0 {
opts = append(opts, node.WithEnableNodeACP(true))
opts.NodeACP().SetEnabled(true)

Check warning on line 73 in cbindings/node.go

View check run for this annotation

Codecov / codecov/patch

cbindings/node.go#L73

Added line #L73 was not covered by tests
}
opts = append(opts, node.WithDocumentACPPath(""))
opts = append(opts, node.WithNodeACPPath(""))

// Configure the replicator retry times. Go from string slice -> time.Duration slice
replicatorRetryTimes := splitCommaSeparatedString(gocOptions.ReplicatorRetryIntervals)
Expand All @@ -91,10 +87,10 @@
replicatorRetryIntervals = append(replicatorRetryIntervals, time.Duration(n)*time.Second)
}
if len(replicatorRetryIntervals) > 0 {
opts = append(opts, db.WithRetryInterval(replicatorRetryIntervals))
opts.DB().SetRetryIntervals(replicatorRetryIntervals)

Check warning on line 90 in cbindings/node.go

View check run for this annotation

Codecov / codecov/patch

cbindings/node.go#L90

Added line #L90 was not covered by tests
}

n, err := node.New(ctx, opts...)
n, err := node.New(ctx, opts)

Check warning on line 93 in cbindings/node.go

View check run for this annotation

Codecov / codecov/patch

cbindings/node.go#L93

Added line #L93 was not covered by tests
if err != nil {
return returnNewNodeResultC(1, err.Error(), nil)
}
Expand Down
8 changes: 2 additions & 6 deletions cli/server_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import (
"github.com/spf13/cobra"

"github.com/sourcenetwork/defradb/acp/dac"
"github.com/sourcenetwork/defradb/cli/config"
"github.com/sourcenetwork/defradb/client/options"
"github.com/sourcenetwork/defradb/errors"
"github.com/sourcenetwork/defradb/internal/db"
acpDB "github.com/sourcenetwork/defradb/internal/db/acp"
Expand All @@ -34,10 +34,7 @@
return errors.New("server-side dump is only supported for the Badger datastore")
}
badgerPath := cfg.GetString("datastore.badger.path")
storeOpts := []node.StoreOpt{
node.WithStorePath(badgerPath),
}
rootstore, _, err := node.NewStore(ctx, storeOpts...)
rootstore, _, err := node.NewStore(ctx, options.NodeStore().SetPath(badgerPath))

Check warning on line 37 in cli/server_dump.go

View check run for this annotation

Codecov / codecov/patch

cli/server_dump.go#L37

Added line #L37 was not covered by tests
if err != nil {
return err
}
Expand All @@ -49,7 +46,6 @@
ctx,
rootstore,
nacInfo,
dac.NoDocumentACP,
)
if err != nil {
return errors.Wrap("failed to initialize database", err)
Expand Down
123 changes: 58 additions & 65 deletions cli/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/sourcenetwork/go-p2p"
"github.com/sourcenetwork/immutable"

"github.com/sourcenetwork/defradb/acp/identity"
"github.com/sourcenetwork/defradb/cli/config"
"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/client/options"
"github.com/sourcenetwork/defradb/crypto"
"github.com/sourcenetwork/defradb/errors"
"github.com/sourcenetwork/defradb/event"
"github.com/sourcenetwork/defradb/http"
"github.com/sourcenetwork/defradb/internal/db"
"github.com/sourcenetwork/defradb/internal/telemetry"
"github.com/sourcenetwork/defradb/keyring"
"github.com/sourcenetwork/defradb/node"
Expand All @@ -51,8 +48,8 @@

const developmentDescription = `Enables a set of features that make development easier but should not be enabled ` +
`in production:
- allows purging of all persisted data
- generates temporary node identity if keyring is disabled`
- allows purging of all persisted data
- generates temporary node identity if one doesn't exist in the keyring`

func MakeStartCommand(ctx context.Context) *cobra.Command {
var identity string
Expand Down Expand Up @@ -90,40 +87,39 @@
replicatorRetryIntervals = append(replicatorRetryIntervals, time.Duration(interval)*time.Second)
}

opts := []node.Option{
node.WithEnableNodeACP(enableNAC),
node.WithDisableP2P(cfg.GetBool("net.p2pDisabled")),
node.WithSourceHubChainID(cfg.GetString("acp.document.sourceHub.ChainID")),
node.WithSourceHubGRPCAddress(cfg.GetString("acp.document.sourceHub.GRPCAddress")),
node.WithSourceHubCometRPCAddress(cfg.GetString("acp.document.sourceHub.CometRPCAddress")),
node.WithEnableDevelopment(cfg.GetBool("development")),
// store options
node.WithStorePath(cfg.GetString("datastore.badger.path")),
node.WithBadgerInMemory(cfg.GetString("datastore.store") == config.ConfigStoreMemory),
// db options
db.WithMaxRetries(cfg.GetInt("datastore.MaxTxnRetries")),
db.WithRetryInterval(replicatorRetryIntervals),
db.WithLensRuntime(db.LensRuntimeType(cfg.GetString("lens.runtime"))),
// net node options
p2p.WithListenAddresses(cfg.GetStringSlice("net.p2pAddresses")...),
p2p.WithEnablePubSub(cfg.GetBool("net.pubSubEnabled")),
p2p.WithEnableRelay(cfg.GetBool("net.relayEnabled")),
p2p.WithBootstrapPeers(cfg.GetStringSlice("net.peers")...),

// http server options
http.WithAddress(cfg.GetString("api.address")),
http.WithAllowedOrigins(cfg.GetStringSlice("api.allowed-origins")...),
http.WithTLSCertPath(cfg.GetString("api.pubKeyPath")),
http.WithTLSKeyPath(cfg.GetString("api.privKeyPath")),
}

if cfg.GetString("datastore.store") != config.ConfigStoreMemory {
inMem := cfg.GetString("datastore.store") == config.ConfigStoreMemory

opts := options.Node().
SetEnableDevelopment(cfg.GetBool("development")).
SetDisableP2P(cfg.GetBool("net.p2pDisabled"))
opts.Store().
SetPath(cfg.GetString("datastore.badger.path")).
SetBadgerInMemory(inMem)
opts.DB().
SetMaxTxnRetries(cfg.GetInt("datastore.MaxTxnRetries")).
SetRetryIntervals(replicatorRetryIntervals).
SetLensRuntime(options.NodeLensRuntimeType(cfg.GetString("lens.runtime")))
opts.P2P().
SetListenAddresses(cfg.GetStringSlice("net.p2pAddresses")...).
SetEnablePubSub(cfg.GetBool("net.pubSubEnabled")).
SetEnableRelay(cfg.GetBool("net.relayEnabled")).
SetBootstrapPeers(cfg.GetStringSlice("net.peers")...)
opts.HTTP().
SetAddress(cfg.GetString("api.address")).
SetAllowedOrigins(cfg.GetStringSlice("api.allowed-origins")...).
SetCertPath(cfg.GetString("api.pubKeyPath")).
SetKeyPath(cfg.GetString("api.privKeyPath"))
opts.DocumentACP().
SetChainID(cfg.GetString("acp.document.sourceHub.ChainID")).
SetGRPCAddress(cfg.GetString("acp.document.sourceHub.GRPCAddress")).
SetCometRPCAddress(cfg.GetString("acp.document.sourceHub.CometRPCAddress"))
opts.NodeACP().
SetEnabled(enableNAC)

if !inMem {
rootDir := mustGetContextRootDir(cmd)
// TODO-ACP: Infuture when we add support for the --no-acp flag when node acp is implemented,
// we can allow starting of db without acp. Currently that can only be done programmatically.
// https://github.com/sourcenetwork/defradb/issues/2271
opts = append(opts, node.WithDocumentACPPath(rootDir))
opts = append(opts, node.WithNodeACPPath(rootDir))
opts.DocumentACP().SetPath(rootDir).
NodeACP().SetPath(rootDir)

Check warning on line 122 in cli/start.go

View check run for this annotation

Codecov / codecov/patch

cli/start.go#L121-L122

Added lines #L121 - L122 were not covered by tests
}

if enableNAC && identity == "" {
Expand All @@ -132,37 +128,41 @@

documentACPType := cfg.GetString("acp.document.type")
if documentACPType != "" {
opts = append(opts, node.WithDocumentACPType(node.DocumentACPType(documentACPType)))
opts.DocumentACP().SetType(options.NodeDocumentACPType(documentACPType))
}

if !cfg.GetBool("keyring.disabled") {
kr, err := openKeyring(cmd)
if err != nil {
return err
}
opts, err = getOrCreatePeerKey(kr, opts)
peerKey, err := getOrCreatePeerKey(kr)

Check warning on line 139 in cli/start.go

View check run for this annotation

Codecov / codecov/patch

cli/start.go#L139

Added line #L139 was not covered by tests
if err != nil {
return err
}
opts.P2P().SetPrivateKey(peerKey)

Check warning on line 143 in cli/start.go

View check run for this annotation

Codecov / codecov/patch

cli/start.go#L143

Added line #L143 was not covered by tests

if !cfg.GetBool("datastore.noencryption") {
opts, err = getOrCreateEncryptionKey(kr, opts)
encKey, err := getOrCreateEncryptionKey(kr)

Check warning on line 146 in cli/start.go

View check run for this annotation

Codecov / codecov/patch

cli/start.go#L146

Added line #L146 was not covered by tests
if err != nil {
return err
}
opts.Store().SetBadgerEncryptionKey(encKey)

Check warning on line 150 in cli/start.go

View check run for this annotation

Codecov / codecov/patch

cli/start.go#L150

Added line #L150 was not covered by tests
}

if !cfg.GetBool("datastore.nosearchableencryption") {
opts, err = getOrCreateSearchableEncryptionKey(kr, opts)
seKey, err := getOrCreateSearchableEncryptionKey(kr)

Check warning on line 154 in cli/start.go

View check run for this annotation

Codecov / codecov/patch

cli/start.go#L154

Added line #L154 was not covered by tests
if err != nil {
return err
}
opts.DB().SetSearchableEncryptionKey(seKey)

Check warning on line 158 in cli/start.go

View check run for this annotation

Codecov / codecov/patch

cli/start.go#L158

Added line #L158 was not covered by tests
}

opts, err = getOrCreateIdentity(kr, opts, cfg)
ident, err := getOrCreateIdentity(kr, cfg)

Check warning on line 161 in cli/start.go

View check run for this annotation

Codecov / codecov/patch

cli/start.go#L161

Added line #L161 was not covered by tests
if err != nil {
return err
}
opts.DB().SetNodeIdentity(ident)

Check warning on line 165 in cli/start.go

View check run for this annotation

Codecov / codecov/patch

cli/start.go#L165

Added line #L165 was not covered by tests

// setup the sourcehub transaction signer
sourceHubKeyName := cfg.GetString("acp.document.sourceHub.KeyName")
Expand All @@ -171,26 +171,23 @@
if err != nil {
return err
}
opts = append(opts, node.WithTxnSigner(immutable.Some[node.TxSigner](signer)))
opts.DocumentACP().SetTxnSigner(signer)

Check warning on line 174 in cli/start.go

View check run for this annotation

Codecov / codecov/patch

cli/start.go#L174

Added line #L174 was not covered by tests
}
}

opts = append(opts, db.WithEnabledSigning(!cfg.GetBool("datastore.nosigning")))
opts.DB().SetEnableSigning(!cfg.GetBool("datastore.nosigning"))

isDevMode := cfg.GetBool("development")
http.IsDevMode = isDevMode
if isDevMode {
cmd.Printf(devModeBanner)
if cfg.GetBool("keyring.disabled") {
var err error
// Generate an ephemeral identity for the node
// TODO: we want to persist this identity so we can restart the node with the same identity
// even in development mode. https://github.com/sourcenetwork/defradb/issues/3148
ident, err := generateIdentity(cfg.GetString("datastore.defaultkeytype"))
if err != nil {
return err
}
opts = append(opts, db.WithNodeIdentity(ident))
opts.DB().SetNodeIdentity(ident)

Check warning on line 190 in cli/start.go

View check run for this annotation

Codecov / codecov/patch

cli/start.go#L190

Added line #L190 was not covered by tests
}
}

Expand All @@ -208,7 +205,7 @@
signalCh := make(chan os.Signal, 1)
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)

n, err := node.New(cmd.Context(), opts...)
n, err := node.New(cmd.Context(), opts)
if err != nil {
return err
}
Expand Down Expand Up @@ -358,7 +355,7 @@
return cmd
}

func getOrCreateEncryptionKey(kr keyring.Keyring, opts []node.Option) ([]node.Option, error) {
func getOrCreateEncryptionKey(kr keyring.Keyring) ([]byte, error) {

Check warning on line 358 in cli/start.go

View check run for this annotation

Codecov / codecov/patch

cli/start.go#L358

Added line #L358 was not covered by tests
encryptionKey, err := kr.Get(encryptionKeyName)
if err != nil {
if !errors.Is(err, keyring.ErrNotFound) {
Expand All @@ -374,13 +371,12 @@
}
log.Info("generated encryption key")
}
opts = append(opts, node.WithBadgerEncryptionKey(encryptionKey))
return opts, nil
return encryptionKey, nil

Check warning on line 374 in cli/start.go

View check run for this annotation

Codecov / codecov/patch

cli/start.go#L374

Added line #L374 was not covered by tests
}

// getOrCreateSearchableEncryptionKey generates or retrieves the searchable encryption key
// from the keyring and adds it to the node options.
func getOrCreateSearchableEncryptionKey(kr keyring.Keyring, opts []node.Option) ([]node.Option, error) {
// from the keyring.
func getOrCreateSearchableEncryptionKey(kr keyring.Keyring) ([]byte, error) {

Check warning on line 379 in cli/start.go

View check run for this annotation

Codecov / codecov/patch

cli/start.go#L379

Added line #L379 was not covered by tests
seKey, err := kr.Get(searchableEncryptionKeyName)
if err != nil {
if !errors.Is(err, keyring.ErrNotFound) {
Expand All @@ -396,13 +392,10 @@
}
log.Info("generated searchable encryption key")
}

// Add the searchable encryption key to node options
opts = append(opts, db.WithSearchableEncryptionKey(seKey))
return opts, nil
return seKey, nil

Check warning on line 395 in cli/start.go

View check run for this annotation

Codecov / codecov/patch

cli/start.go#L395

Added line #L395 was not covered by tests
}

func getOrCreatePeerKey(kr keyring.Keyring, opts []node.Option) ([]node.Option, error) {
func getOrCreatePeerKey(kr keyring.Keyring) ([]byte, error) {

Check warning on line 398 in cli/start.go

View check run for this annotation

Codecov / codecov/patch

cli/start.go#L398

Added line #L398 was not covered by tests
peerKey, err := kr.Get(peerKeyName)
if err != nil && errors.Is(err, keyring.ErrNotFound) {
peerKey, err = crypto.GenerateEd25519()
Expand All @@ -417,10 +410,10 @@
} else if err != nil {
return nil, err
}
return append(opts, p2p.WithPrivateKey(peerKey)), nil
return peerKey, nil

Check warning on line 413 in cli/start.go

View check run for this annotation

Codecov / codecov/patch

cli/start.go#L413

Added line #L413 was not covered by tests
}

func getOrCreateIdentity(kr keyring.Keyring, opts []node.Option, cfg *viper.Viper) ([]node.Option, error) {
func getOrCreateIdentity(kr keyring.Keyring, cfg *viper.Viper) (identity.Identity, error) {

Check warning on line 416 in cli/start.go

View check run for this annotation

Codecov / codecov/patch

cli/start.go#L416

Added line #L416 was not covered by tests
identityBytes, err := kr.Get(nodeIdentityKeyName)
if err != nil {
if !errors.Is(err, keyring.ErrNotFound) {
Expand Down Expand Up @@ -449,7 +442,7 @@
if err != nil {
return nil, err
}
return getOrCreateIdentity(kr, opts, cfg)
return getOrCreateIdentity(kr, cfg)

Check warning on line 445 in cli/start.go

View check run for this annotation

Codecov / codecov/patch

cli/start.go#L445

Added line #L445 was not covered by tests
}
keyType := string(identityBytes[:sepPos])
privateKey, err := crypto.PrivateKeyFromBytes(crypto.KeyType(keyType), identityBytes[sepPos+1:])
Expand All @@ -461,7 +454,7 @@
return nil, err
}

return append(opts, db.WithNodeIdentity(ident)), nil
return ident, nil

Check warning on line 457 in cli/start.go

View check run for this annotation

Codecov / codecov/patch

cli/start.go#L457

Added line #L457 was not covered by tests
}

func generateIdentity(keyType string) (identity.FullIdentity, error) {
Expand Down
Loading
Loading