diff --git a/go.mod b/go.mod index c51b84bdf89a6836d872ff2d34f6a45d55206833..d8ea94800e686294138a61d6c5cfd4eb695cf5f7 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/googollee/go-engine.io v1.4.3-0.20190924125625-798118fc0dd2 github.com/googollee/go-socket.io v1.4.3-0.20191204093753-683f8725b6d0 github.com/gorilla/websocket v1.4.1 - github.com/iotaledger/hive.go v0.0.0-20200212114128-1460dba4a6b0 + github.com/iotaledger/hive.go v0.0.0-20200217140357-8f1ea1f52085 github.com/iotaledger/iota.go v1.0.0-beta.14 github.com/labstack/echo v3.3.10+incompatible github.com/labstack/gommon v0.3.0 // indirect diff --git a/go.sum b/go.sum index a72469bc23877dbdd3c26167d4e37561f2ae3247..ccf7ed45bbe3db76d7f7e6d29cf5b386c13fb12a 100644 --- a/go.sum +++ b/go.sum @@ -125,6 +125,8 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/iotaledger/hive.go v0.0.0-20200212114128-1460dba4a6b0 h1:AXUiVkx3QWQPzEIpmHJEAjMmZCzx8VKF342+vouRbic= github.com/iotaledger/hive.go v0.0.0-20200212114128-1460dba4a6b0/go.mod h1:wj3bFHlcX0NiEOWu5+WOg/MI/5N7PKCFnyaziaylB64= +github.com/iotaledger/hive.go v0.0.0-20200217140357-8f1ea1f52085 h1:gkxkCRUlAszGx1qgN+QxnVI5VvX7bxH0/2hqz8l8lSo= +github.com/iotaledger/hive.go v0.0.0-20200217140357-8f1ea1f52085/go.mod h1:wj3bFHlcX0NiEOWu5+WOg/MI/5N7PKCFnyaziaylB64= github.com/iotaledger/iota.go v1.0.0-beta.9/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8= github.com/iotaledger/iota.go v1.0.0-beta.14 h1:Oeb28MfBuJEeXcGrLhTCJFtbsnc8y1u7xidsAmiOD5A= github.com/iotaledger/iota.go v1.0.0-beta.14/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8= diff --git a/packages/binary/tangle/tangle.go b/packages/binary/tangle/tangle.go index 9033cfdd65e7360ee3c364f2ed3e47705f6a7c47..876c0d37917e45e4d356482993a9ab07c1344d67 100644 --- a/packages/binary/tangle/tangle.go +++ b/packages/binary/tangle/tangle.go @@ -4,6 +4,7 @@ import ( "container/list" "time" + "github.com/dgraph-io/badger/v2" "github.com/iotaledger/hive.go/types" "github.com/iotaledger/goshimmer/packages/binary/storageprefix" @@ -37,13 +38,13 @@ type Tangle struct { } // Constructor for the tangle. -func New(storageId []byte) (result *Tangle) { +func New(badgerInstance *badger.DB, storageId []byte) (result *Tangle) { result = &Tangle{ storageId: storageId, - transactionStorage: objectstorage.New(append(storageId, storageprefix.TangleTransaction...), transaction.FromStorage), - transactionMetadataStorage: objectstorage.New(append(storageId, storageprefix.TangleTransactionMetadata...), transactionmetadata.FromStorage), - approverStorage: objectstorage.New(append(storageId, storageprefix.TangleApprovers...), approver.FromStorage, objectstorage.PartitionKey(transaction.IdLength, transaction.IdLength)), - missingTransactionsStorage: objectstorage.New(append(storageId, storageprefix.TangleMissingTransaction...), missingtransaction.FromStorage), + transactionStorage: objectstorage.New(badgerInstance, append(storageId, storageprefix.TangleTransaction...), transaction.FromStorage), + transactionMetadataStorage: objectstorage.New(badgerInstance, append(storageId, storageprefix.TangleTransactionMetadata...), transactionmetadata.FromStorage), + approverStorage: objectstorage.New(badgerInstance, append(storageId, storageprefix.TangleApprovers...), approver.FromStorage, objectstorage.PartitionKey(transaction.IdLength, transaction.IdLength)), + missingTransactionsStorage: objectstorage.New(badgerInstance, append(storageId, storageprefix.TangleMissingTransaction...), missingtransaction.FromStorage), Events: *newEvents(), } diff --git a/packages/binary/tangle/tangle_test.go b/packages/binary/tangle/tangle_test.go index 33420e87dacbb7611078bcff3875665401de8e12..f40da0a91d6bd1e15df1ac5e78ea2ad6eeca6bf3 100644 --- a/packages/binary/tangle/tangle_test.go +++ b/packages/binary/tangle/tangle_test.go @@ -5,16 +5,24 @@ import ( "testing" "time" + "github.com/dgraph-io/badger/v2" "github.com/iotaledger/hive.go/events" "github.com/iotaledger/goshimmer/packages/binary/identity" "github.com/iotaledger/goshimmer/packages/binary/tangle/model/transaction" "github.com/iotaledger/goshimmer/packages/binary/tangle/model/transaction/payload/data" "github.com/iotaledger/goshimmer/packages/binary/tangle/model/transactionmetadata" + "github.com/iotaledger/goshimmer/packages/database" ) +var testDatabase *badger.DB + +func init() { + testDatabase = database.GetBadgerInstance() +} + func BenchmarkTangle_AttachTransaction(b *testing.B) { - tangle := New([]byte("TEST_BINARY_TANGLE")) + tangle := New(testDatabase, []byte("TEST_BINARY_TANGLE")) if err := tangle.Prune(); err != nil { b.Error(err) @@ -39,7 +47,7 @@ func BenchmarkTangle_AttachTransaction(b *testing.B) { } func TestTangle_AttachTransaction(t *testing.T) { - tangle := New([]byte("TEST_BINARY_TANGLE")) + tangle := New(testDatabase, []byte("TEST_BINARY_TANGLE")) if err := tangle.Prune(); err != nil { t.Error(err) diff --git a/plugins/config/plugin.go b/plugins/config/plugin.go index 1dcccb490d38bd6a1a7e9d5a40ea2e76d1901d48..0626fa17396b321ac567b28a3fb536bac9b39d42 100644 --- a/plugins/config/plugin.go +++ b/plugins/config/plugin.go @@ -4,6 +4,7 @@ import ( "github.com/iotaledger/hive.go/node" ) +// define the plugin as a placeholder, so the init methods get executed accordingly var PLUGIN = node.NewPlugin("Config", node.Enabled, run) func run(ctx *node.Plugin) { diff --git a/plugins/logger/plugin.go b/plugins/logger/plugin.go index 8dde32211cf93d76be36538bff0776bd09bc59c0..c256469042773a54dd2e853fefa4b6e5feba7e12 100644 --- a/plugins/logger/plugin.go +++ b/plugins/logger/plugin.go @@ -4,6 +4,7 @@ import ( "github.com/iotaledger/hive.go/node" ) +// define the plugin as a placeholder, so the init methods get executed accordingly var PLUGIN = node.NewPlugin("Logger", node.Enabled, run) func run(ctx *node.Plugin) { diff --git a/plugins/tangle/tangle.go b/plugins/tangle/tangle.go index 6862e9aa484d0a421c9d98c2c82f818861e08f6d..23edfe1fd03392590e9e5929308ed8b6e55395a8 100644 --- a/plugins/tangle/tangle.go +++ b/plugins/tangle/tangle.go @@ -7,6 +7,7 @@ import ( "github.com/iotaledger/goshimmer/packages/binary/tangle/tipselector" "github.com/iotaledger/goshimmer/packages/binary/tangle/transactionparser" "github.com/iotaledger/goshimmer/packages/binary/tangle/transactionrequester" + "github.com/iotaledger/goshimmer/packages/database" "github.com/iotaledger/goshimmer/packages/shutdown" "github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/events" @@ -36,7 +37,7 @@ func configure(*node.Plugin) { TransactionParser = transactionparser.New() TransactionRequester = transactionrequester.New() TipSelector = tipselector.New() - Instance = tangle.New(storageprefix.Mainnet) + Instance = tangle.New(database.GetBadgerInstance(), storageprefix.Mainnet) // setup TransactionParser TransactionParser.Events.TransactionParsed.Attach(events.NewClosure(func(transaction *transaction.Transaction) {