Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ require (
golang.org/x/mod v0.4.2 // indirect
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect
golang.org/x/tools v0.1.0 // indirect
gopkg.in/DataDog/dd-trace-go.v1 v1.29.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,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 @@ -947,6 +963,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 @@ -2257,6 +2277,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
50 changes: 50 additions & 0 deletions lib/block_view_flush.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,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 +414,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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// If the LikeEntry has isDeleted=true then there's nothing to do because
// If the ReactEntry 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// If the LikeEntry has (isDeleted = false) then we put the corresponding
// If the ReactEntry 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