From 4bfcb797ec5fdfe7d9af18952c5ff1368f8d7020 Mon Sep 17 00:00:00 2001 From: Hans Moog <hm@mkjc.net> Date: Tue, 9 Jul 2019 11:50:59 +0200 Subject: [PATCH] Feat: bundleHash gets calculated for value bundles --- go.sum | 2 ++ plugins/bundleprocessor/bundleprocessor.go | 12 +++++++++--- plugins/bundleprocessor/bundleprocessor_test.go | 1 + plugins/validator/plugin.go | 3 +-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/go.sum b/go.sum index 9ca44d69..4be9aee6 100644 --- a/go.sum +++ b/go.sum @@ -19,6 +19,7 @@ github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4 github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/ethereum/go-ethereum v1.8.27 h1:d+gkiLaBDk5fn3Pe/xNVaMrB/ozI+AUB2IlVBp29IrY= github.com/ethereum/go-ethereum v1.8.27/go.mod h1:PwpWDrCLZrV+tfrhqqF6kPknbISMHaJv9Ln3kPCZLwY= +github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= @@ -104,6 +105,7 @@ golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed h1:uPxWBzB3+mlnjy9W58qY1j/cj golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= diff --git a/plugins/bundleprocessor/bundleprocessor.go b/plugins/bundleprocessor/bundleprocessor.go index 30c8b6d5..9dade9b6 100644 --- a/plugins/bundleprocessor/bundleprocessor.go +++ b/plugins/bundleprocessor/bundleprocessor.go @@ -1,7 +1,7 @@ package bundleprocessor import ( - "github.com/iotadevelopment/go/packages/ternary" + "github.com/iotaledger/goshimmer/packages/curl" "github.com/iotaledger/goshimmer/packages/errors" "github.com/iotaledger/goshimmer/packages/model/bundle" "github.com/iotaledger/goshimmer/packages/model/transactionmetadata" @@ -54,12 +54,18 @@ func ProcessSolidBundleHead(headTransaction *value_transaction.ValueTransaction) newBundle.SetTransactionHashes(mapTransactionsToTransactionHashes(bundleTransactions)) if newBundle.IsValueBundle() { - var concatenatedBundleEssences = make(ternary.Trits, len(bundleTransactions)*value_transaction.BUNDLE_ESSENCE_SIZE) + var concatenatedBundleEssences = make(trinary.Trits, len(bundleTransactions)*value_transaction.BUNDLE_ESSENCE_SIZE) for i, bundleTransaction := range bundleTransactions { copy(concatenatedBundleEssences[value_transaction.BUNDLE_ESSENCE_SIZE*i:value_transaction.BUNDLE_ESSENCE_SIZE*(i+1)], bundleTransaction.GetBundleEssence()) } - // calc + set bundle hash + var resp = make(trinary.Trits, 243) + + hasher := curl.NewCurl(243, 81) + hasher.Absorb(concatenatedBundleEssences, 0, len(concatenatedBundleEssences)) + hasher.Squeeze(resp, 0, 243) + + newBundle.SetBundleEssenceHash(trinary.MustTritsToTrytes(resp)) } Events.BundleSolid.Trigger(newBundle, bundleTransactions) diff --git a/plugins/bundleprocessor/bundleprocessor_test.go b/plugins/bundleprocessor/bundleprocessor_test.go index 5da9cc4d..ee4cc3d4 100644 --- a/plugins/bundleprocessor/bundleprocessor_test.go +++ b/plugins/bundleprocessor/bundleprocessor_test.go @@ -29,6 +29,7 @@ func TestProcessSolidBundleHead(t *testing.T) { Events.BundleSolid.Attach(events.NewClosure(func(bundle *bundle.Bundle, transactions []*value_transaction.ValueTransaction) { fmt.Println("IT HAPPENED") fmt.Println(bundle.GetHash()) + fmt.Println(bundle.GetBundleEssenceHash()) })) result, err := ProcessSolidBundleHead(tx1) diff --git a/plugins/validator/plugin.go b/plugins/validator/plugin.go index dce2129b..c0c7b64b 100644 --- a/plugins/validator/plugin.go +++ b/plugins/validator/plugin.go @@ -8,7 +8,6 @@ import ( "github.com/iotaledger/goshimmer/plugins/bundleprocessor" "github.com/iotaledger/iota.go/address" . "github.com/iotaledger/iota.go/consts" - "github.com/iotaledger/iota.go/kerl" "github.com/iotaledger/iota.go/signing" . "github.com/iotaledger/iota.go/trinary" ) @@ -63,7 +62,7 @@ func validateSignatures(bundleHash Hash, txs []*value_transaction.ValueTransacti } // validate all the fragments against the address using Kerl - valid, err := signing.ValidateSignatures(address, fragments, bundleHash, kerl.NewKerl()) + valid, err := signing.ValidateSignatures(address, fragments, bundleHash, signing.NewKerl) if err != nil { return false, err } -- GitLab