From 724ca7a358b8c66605195fbba4d38287cc318070 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Thu, 15 Jul 2021 10:42:46 +0200 Subject: [PATCH] kvdb: exclude anything bbolt related from JS builds Since bbolt uses syscalls for memory mapping that aren't available in JS/WASM builds, we need to make sure we don't reference that code at all. Otherwise we can't use parts of lnd as a library in projects that are being compiled down to a WASM binary. --- kvdb/backend.go | 2 ++ kvdb/backend_js.go | 48 ++++++++++++++++++++++++++++++++++++++++++++ kvdb/bolt_compact.go | 2 ++ 3 files changed, 52 insertions(+) create mode 100644 kvdb/backend_js.go diff --git a/kvdb/backend.go b/kvdb/backend.go index 23dccddf..a5307dfa 100644 --- a/kvdb/backend.go +++ b/kvdb/backend.go @@ -1,3 +1,5 @@ +// +build !js + package kvdb import ( diff --git a/kvdb/backend_js.go b/kvdb/backend_js.go new file mode 100644 index 00000000..f1774408 --- /dev/null +++ b/kvdb/backend_js.go @@ -0,0 +1,48 @@ +package kvdb + +import ( + "fmt" + "time" +) + +// BoltBackendConfig is a struct that holds settings specific to the bolt +// database backend. +type BoltBackendConfig struct { + // DBPath is the directory path in which the database file should be + // stored. + DBPath string + + // DBFileName is the name of the database file. + DBFileName string + + // NoFreelistSync, if true, prevents the database from syncing its + // freelist to disk, resulting in improved performance at the expense of + // increased startup time. + NoFreelistSync bool + + // AutoCompact specifies if a Bolt based database backend should be + // automatically compacted on startup (if the minimum age of the + // database file is reached). This will require additional disk space + // for the compacted copy of the database but will result in an overall + // lower database size after the compaction. + AutoCompact bool + + // AutoCompactMinAge specifies the minimum time that must have passed + // since a bolt database file was last compacted for the compaction to + // be considered again. + AutoCompactMinAge time.Duration + + // DBTimeout specifies the timeout value to use when opening the wallet + // database. + DBTimeout time.Duration +} + +// GetBoltBackend opens (or creates if doesn't exits) a bbolt backed database +// and returns a kvdb.Backend wrapping it. +func GetBoltBackend(cfg *BoltBackendConfig) (Backend, error) { + return nil, fmt.Errorf("bolt backend not supported in WebAssembly") +} + +func GetTestBackend(path, name string) (Backend, func(), error) { + return nil, nil, fmt.Errorf("bolt backend not supported in WebAssembly") +} diff --git a/kvdb/bolt_compact.go b/kvdb/bolt_compact.go index 9d2676d7..66203ff9 100644 --- a/kvdb/bolt_compact.go +++ b/kvdb/bolt_compact.go @@ -2,6 +2,8 @@ // implemented in this file: // https://github.com/etcd-io/bbolt/blob/master/cmd/bbolt/main.go +// +build !js + package kvdb import (