Skip to content

Commit

Permalink
Merge pull request #42 from quorumcontrol/feature/fixed-tupelo-txn-ba…
Browse files Browse the repository at this point in the history
…tch-size

Use a fixed batch size for tupelo txns
  • Loading branch information
Wes Morgan authored Mar 24, 2020
2 parents 3dee83f + 27e9c0b commit 512ba95
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions storage/siaskynet/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"go.uber.org/zap"
)

const TupeloTxnBatchSize = 75

var log = logging.Logger("dgit.storage.siaskynet")

type ObjectStorage struct {
Expand Down Expand Up @@ -126,9 +128,9 @@ func downloadObjectFromSkynet(s *Skynet, link string) (plumbing.EncodedObject, e
resultC, errC := s.DownloadObject(link)

select {
case err := <- errC:
case err := <-errC:
return nil, err
case o := <- resultC:
case o := <-resultC:
return o, nil
}
}
Expand Down Expand Up @@ -188,10 +190,19 @@ func (ot *ObjectTransaction) Commit() error {
}

if len(skylinks) > 0 {
ot.log.Debugf("saving %d Skylinks in transaction to repo chaintree", len(skylinks))
_, err := ot.storage.Tupelo.PlayTransactions(ot.storage.Ctx, ot.storage.ChainTree, ot.storage.PrivateKey, tupeloTxns)
if err != nil {
return err
txnBatch := make([]*transactions.Transaction, 0)
lastIdx := len(tupeloTxns) - 1
for i, t := range tupeloTxns {
batchIdx := (i + 1) % TupeloTxnBatchSize
txnBatch = append(txnBatch, t)
if batchIdx == 0 || i == lastIdx {
ot.log.Debugf("saving %d Skylinks in transaction to repo chaintree", len(txnBatch))
_, err := ot.storage.Tupelo.PlayTransactions(ot.storage.Ctx, ot.storage.ChainTree, ot.storage.PrivateKey, txnBatch)
if err != nil {
return err
}
txnBatch = make([]*transactions.Transaction, 0)
}
}
}

Expand Down

0 comments on commit 512ba95

Please sign in to comment.