Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,14 @@ require (
go.opencensus.io v0.23.0 // indirect
golang.org/x/mod v0.4.2 // indirect
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
<<<<<<< HEAD
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac // indirect
golang.org/x/text v0.3.6 // indirect
=======
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/text v0.3.7 // indirect
>>>>>>> fb4e83e6a39e4f8e22d0729d4bcda3912e4f4141
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect
golang.org/x/tools v0.1.0 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,8 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 h1:Hir2P/De0WpUhtrKGGjvSb2YxUgyZ7EFOSLIcSSpiwE=
Expand Down
24 changes: 24 additions & 0 deletions lib/block_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ type UtxoView struct {
// Like data
LikeKeyToLikeEntry map[LikeKey]*LikeEntry

// React data
ReactionKeyToReactionEntry map[ReactionKey]*ReactionEntry

// Repost data
RepostKeyToRepostEntry map[RepostKey]*RepostEntry

Expand Down Expand Up @@ -145,6 +148,9 @@ func (bav *UtxoView) _ResetViewMappingsAfterFlush() {
// Like data
bav.LikeKeyToLikeEntry = make(map[LikeKey]*LikeEntry)

// React data
bav.ReactionKeyToReactionEntry = make(map[ReactionKey]*ReactionEntry)

// Repost data
bav.RepostKeyToRepostEntry = make(map[RepostKey]*RepostEntry)

Expand Down Expand Up @@ -281,6 +287,16 @@ func (bav *UtxoView) CopyUtxoView() (*UtxoView, error) {
newView.LikeKeyToLikeEntry[likeKey] = &newLikeEntry
}

// Copy the react data
newView.ReactionKeyToReactionEntry = make(map[ReactionKey]*ReactionEntry, len(bav.ReactionKeyToReactionEntry))
for reactKey, reactEntry := range bav.ReactionKeyToReactionEntry {
if reactEntry == nil {
continue
}
newReactEntry := *reactEntry
newView.ReactionKeyToReactionEntry[reactKey] = &newReactEntry
}

// Copy the repost data
newView.RepostKeyToRepostEntry = make(map[RepostKey]*RepostEntry, len(bav.RepostKeyToRepostEntry))
for repostKey, repostEntry := range bav.RepostKeyToRepostEntry {
Expand Down Expand Up @@ -948,6 +964,10 @@ func (bav *UtxoView) DisconnectTransaction(currentTxn *MsgDeSoTxn, txnHash *Bloc
return bav._disconnectLike(
OperationTypeLike, currentTxn, txnHash, utxoOpsForTxn, blockHeight)

} else if currentTxn.TxnMeta.GetTxnType() == TxnTypeReact {
return bav._disconnectReact(
OperationTypeReact, currentTxn, txnHash, utxoOpsForTxn, blockHeight)

} else if currentTxn.TxnMeta.GetTxnType() == TxnTypeCreatorCoin {
return bav._disconnectCreatorCoin(
OperationTypeCreatorCoin, currentTxn, txnHash, utxoOpsForTxn, blockHeight)
Expand Down Expand Up @@ -2310,6 +2330,10 @@ func (bav *UtxoView) _connectTransaction(txn *MsgDeSoTxn, txHash *BlockHash,
totalInput, totalOutput, utxoOpsForTxn, err =
bav._connectLike(txn, txHash, blockHeight, verifySignatures)

} else if txn.TxnMeta.GetTxnType() == TxnTypeReact {
totalInput, totalOutput, utxoOpsForTxn, err =
bav._connectReact(txn, txHash, blockHeight, verifySignatures)

} else if txn.TxnMeta.GetTxnType() == TxnTypeCreatorCoin {
totalInput, totalOutput, utxoOpsForTxn, err =
bav._connectCreatorCoin(
Expand Down
51 changes: 50 additions & 1 deletion lib/block_view_flush.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package lib
import (
"fmt"
"github.com/btcsuite/btcd/btcec"
"github.com/dgraph-io/badger/v3"
"github.com/golang/glog"
"github.com/pkg/errors"
"reflect"
Expand Down Expand Up @@ -66,6 +65,9 @@ func (bav *UtxoView) FlushToDbWithTxn(txn *badger.Txn, blockHeight uint64) error
if err := bav._flushLikeEntriesToDbWithTxn(txn); err != nil {
return err
}
if err := bav._flushReactEntriesToDbWithTxn(txn); err != nil {
return err
}
if err := bav._flushFollowEntriesToDbWithTxn(txn); err != nil {
return err
}
Expand Down Expand Up @@ -411,6 +413,53 @@ func (bav *UtxoView) _flushLikeEntriesToDbWithTxn(txn *badger.Txn) error {
return nil
}

func (bav *UtxoView) _flushReactEntriesToDbWithTxn(txn *badger.Txn) error {

// Go through all the entries in the ReactionKeyToReactionEntry map.
for reactKeyIter, reactEntry := range bav.ReactionKeyToReactionEntry {
// Make a copy of the iterator since we make references to it below.
reactKey := reactKeyIter

// Sanity-check that the ReactKey computed from the ReactEntry is
// equal to the ReactKey that maps to that entry.
reactKeyInEntry := MakeReactionKey(reactEntry.ReactorPubKey, *reactEntry.ReactedPostHash, reactEntry.ReactEmoji)
if reactKeyInEntry != reactKey {
return fmt.Errorf("_flushReactEntriesToDbWithTxn: ReactEntry has "+
"ReactKey: %v, which doesn't match the ReactKeyToReactEntry map key %v",
&reactKeyInEntry, &reactKey)
}

// Delete the existing mappings in the db for this ReactKey. They will be re-added
// if the corresponding entry in memory has isDeleted=false.
if err := DbDeleteReactMappingsWithTxn(
txn, reactKey.ReactorPubKey[:], reactKey.ReactedPostHash, reactKey.ReactEmoji); err != nil {

return errors.Wrapf(
err, "_flushReactEntriesToDbWithTxn: Problem deleting mappings "+
"for LikeKey: %v: ", &reactKey)
}
}

// Go through all the entries in the LikeKeyToLikeEntry map.
for _, reactEntry := range bav.ReactionKeyToReactionEntry {

if reactEntry.isDeleted {
// If the LikeEntry has isDeleted=true then there's nothing to do because
// we already deleted the entry above.
} else {
// If the LikeEntry has (isDeleted = false) then we put the corresponding
// mappings for it into the db.
if err := DbPutReactMappingsWithTxn(
txn, reactEntry.ReactorPubKey, *reactEntry.ReactedPostHash, reactEntry.ReactEmoji); err != nil {

return err
}
}
}

return nil
}

func (bav *UtxoView) _flushFollowEntriesToDbWithTxn(txn *badger.Txn) error {

// Go through all the entries in the FollowKeyToFollowEntry map.
Expand Down
Loading