diff --git a/packages/datastructure/lru_cache.go b/packages/datastructure/lru_cache.go index c07da3ba485bce91765004d20091a7247546d7f7..f2701bcc27e51d3b40318d3e9c99a1ae2ba855c4 100644 --- a/packages/datastructure/lru_cache.go +++ b/packages/datastructure/lru_cache.go @@ -2,6 +2,8 @@ package datastructure import ( "sync" + + "github.com/iotaledger/goshimmer/packages/typeutils" ) type lruCacheElement struct { @@ -101,7 +103,7 @@ func (cache *LRUCache) ComputeIfPresent(key interface{}, callback func(value int if entry, exists := cache.directory[key]; exists { result = entry.GetValue().(*lruCacheElement).value - if callbackResult := callback(result); result != nil { + if callbackResult := callback(result); !typeutils.IsInterfaceNil(callbackResult) { result = callbackResult cache.set(key, callbackResult) diff --git a/packages/filter/byte_array_filter.go b/packages/filter/byte_array_filter.go index ba5aca0a4910142c3c570849b2861203466367b8..d8cb89fe010d8571331a2f4dbc0e31b328cbf275 100644 --- a/packages/filter/byte_array_filter.go +++ b/packages/filter/byte_array_filter.go @@ -3,7 +3,7 @@ package filter import ( "sync" - "github.com/iotaledger/goshimmer/packages/typeconversion" + "github.com/iotaledger/goshimmer/packages/typeutils" ) type ByteArrayFilter struct { @@ -25,20 +25,20 @@ func (filter *ByteArrayFilter) Contains(byteArray []byte) bool { filter.mutex.RLock() defer filter.mutex.RUnlock() - _, exists := filter.byteArraysByKey[typeconversion.BytesToString(byteArray)] + _, exists := filter.byteArraysByKey[typeutils.BytesToString(byteArray)] return exists } func (filter *ByteArrayFilter) Add(byteArray []byte) bool { - key := typeconversion.BytesToString(byteArray) + key := typeutils.BytesToString(byteArray) filter.mutex.Lock() defer filter.mutex.Unlock() if _, exists := filter.byteArraysByKey[key]; !exists { if len(filter.byteArrays) == filter.size { - delete(filter.byteArraysByKey, typeconversion.BytesToString(filter.byteArrays[0])) + delete(filter.byteArraysByKey, typeutils.BytesToString(filter.byteArrays[0])) filter.byteArrays = append(filter.byteArrays[1:], byteArray) } else { diff --git a/packages/model/approvers/approvers.go b/packages/model/approvers/approvers.go new file mode 100644 index 0000000000000000000000000000000000000000..be5f753073d7adc2b1f1b9b754aa8fb957114253 --- /dev/null +++ b/packages/model/approvers/approvers.go @@ -0,0 +1,22 @@ +package approvers + +import ( + "sync" + + "github.com/iotaledger/goshimmer/packages/ternary" +) + +type Approvers struct { + hash ternary.Trinary + hashes map[ternary.Trinary]bool + hashesMutex sync.RWMutex + modified bool +} + +func NewApprovers(hash ternary.Trinary) *Approvers { + return &Approvers{ + hash: hash, + hashes: make(map[ternary.Trinary]bool), + modified: false, + } +} diff --git a/packages/typeconversion/typeconversion.go b/packages/typeutils/typeutils.go similarity index 74% rename from packages/typeconversion/typeconversion.go rename to packages/typeutils/typeutils.go index ed053ee8bc431c7c652a23774d381d0a06ce3c71..e59ebe2e778da37709e8485315763672618d22d9 100644 --- a/packages/typeconversion/typeconversion.go +++ b/packages/typeutils/typeutils.go @@ -1,4 +1,4 @@ -package typeconversion +package typeutils import ( "reflect" @@ -16,3 +16,7 @@ func StringToBytes(str string) []byte { return *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{Data: hdr.Data, Len: hdr.Len, Cap: hdr.Len})) } + +func IsInterfaceNil(param interface{}) bool { + return param == nil || (*[2]uintptr)(unsafe.Pointer(¶m))[1] == 0 +} diff --git a/plugins/gossip/plugin.go b/plugins/gossip/plugin.go index df702928ff8acdbb4b852dc9146c12c0ec3fbd86..0f02bd1404f577c1d265e239493aeec712e97ead 100644 --- a/plugins/gossip/plugin.go +++ b/plugins/gossip/plugin.go @@ -1,8 +1,6 @@ package gossip import ( - "github.com/iotaledger/goshimmer/packages/events" - "github.com/iotaledger/goshimmer/packages/model/meta_transaction" "github.com/iotaledger/goshimmer/packages/node" ) @@ -12,10 +10,6 @@ func configure(plugin *node.Plugin) { configureNeighbors(plugin) configureServer(plugin) configureSendQueue(plugin) - - Events.ReceiveTransaction.Attach(events.NewClosure(func(tx *meta_transaction.MetaTransaction) { - plugin.LogDebug("Received TX " + string(tx.GetHash())) - })) } func run(plugin *node.Plugin) { diff --git a/plugins/gossip/send_queue.go b/plugins/gossip/send_queue.go index 354c0c3bf0557265e7806d249a20b38e294ef667..1945b7e432966a54c3913545ac9cc9ae8a01661f 100644 --- a/plugins/gossip/send_queue.go +++ b/plugins/gossip/send_queue.go @@ -150,7 +150,7 @@ var connectedNeighborsMutex sync.RWMutex var sendQueue = make(chan *meta_transaction.MetaTransaction, SEND_QUEUE_SIZE) const ( - SEND_QUEUE_SIZE = 500 + SEND_QUEUE_SIZE = 50000 ) // endregion /////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/plugins/tangle/approvers.go b/plugins/tangle/approvers.go index cdf3c7b4af96827c351f0f209b403d7cc0a9fdca..f10291d47b8a4147c50625938fb46b6fc2ef8428 100644 --- a/plugins/tangle/approvers.go +++ b/plugins/tangle/approvers.go @@ -9,7 +9,7 @@ import ( "github.com/iotaledger/goshimmer/packages/datastructure" "github.com/iotaledger/goshimmer/packages/errors" "github.com/iotaledger/goshimmer/packages/ternary" - "github.com/iotaledger/goshimmer/packages/typeconversion" + "github.com/iotaledger/goshimmer/packages/typeutils" ) // region global public api //////////////////////////////////////////////////////////////////////////////////////////// @@ -132,13 +132,13 @@ func (approvers *Approvers) Unmarshal(data []byte) (err errors.IdentifiableError approvers.hashesMutex.Lock() - approvers.hash = ternary.Trinary(typeconversion.BytesToString(data[MARSHALLED_APPROVERS_HASH_START:MARSHALLED_APPROVERS_HASH_END])) + approvers.hash = ternary.Trinary(typeutils.BytesToString(data[MARSHALLED_APPROVERS_HASH_START:MARSHALLED_APPROVERS_HASH_END])) approvers.hashes = make(map[ternary.Trinary]bool, hashesCount) for i := uint64(0); i < hashesCount; i++ { var HASH_START = MARSHALLED_APPROVERS_HASHES_START + i*(MARSHALLED_APPROVERS_HASH_SIZE) var HASH_END = HASH_START * MARSHALLED_APPROVERS_HASH_SIZE - approvers.hashes[ternary.Trinary(typeconversion.BytesToString(data[HASH_START:HASH_END]))] = true + approvers.hashes[ternary.Trinary(typeutils.BytesToString(data[HASH_START:HASH_END]))] = true } approvers.hashesMutex.Unlock() diff --git a/plugins/tangle/transaction_metadata.go b/plugins/tangle/transaction_metadata.go index c617f0c97a02a2f4e64864e62e3fe113a7ac9b56..4b0dc22dd61b0b7e12ba5a1e106094c51496f569 100644 --- a/plugins/tangle/transaction_metadata.go +++ b/plugins/tangle/transaction_metadata.go @@ -7,7 +7,7 @@ import ( "github.com/iotaledger/goshimmer/packages/bitutils" "github.com/iotaledger/goshimmer/packages/errors" "github.com/iotaledger/goshimmer/packages/ternary" - "github.com/iotaledger/goshimmer/packages/typeconversion" + "github.com/iotaledger/goshimmer/packages/typeutils" ) // region type definition and constructor ////////////////////////////////////////////////////////////////////////////// @@ -228,7 +228,7 @@ func (metadata *TransactionMetadata) Unmarshal(data []byte) errors.IdentifiableE metadata.finalizedMutex.Lock() defer metadata.finalizedMutex.Unlock() - metadata.hash = ternary.Trinary(typeconversion.BytesToString(data[MARSHALLED_HASH_START:MARSHALLED_HASH_END])) + metadata.hash = ternary.Trinary(typeutils.BytesToString(data[MARSHALLED_HASH_START:MARSHALLED_HASH_END])) if err := metadata.receivedTime.UnmarshalBinary(data[MARSHALLED_RECEIVED_TIME_START:MARSHALLED_RECEIVED_TIME_END]); err != nil { return ErrUnmarshalFailed.Derive(err, "could not unmarshal the received time")