diff --git a/sphinx.go b/sphinx.go index f8e1a15..9b7a97a 100644 --- a/sphinx.go +++ b/sphinx.go @@ -7,6 +7,7 @@ import ( "fmt" "io" "math/big" + "sync" "github.com/btcsuite/btcd/btcec" "github.com/btcsuite/btcd/chaincfg" @@ -701,6 +702,8 @@ type Tx struct { // only be accessed if the index is *not* included in the replay set, or // otherwise failed any other stage of the processing. packets []ProcessedPacket + + sync.Mutex } // BeginTxn creates a new transaction that can later be committed back to the @@ -751,6 +754,9 @@ func (t *Tx) ProcessOnionPacket(seqNum uint16, onionPkt *OnionPacket, return err } + t.Lock() + defer t.Unlock() + // Add the hash prefix to pending batch of shared secrets that will be // written later via Commit(). err = t.batch.Put(seqNum, hashPrefix, incomingCltv)