Skip to content

Commit

Permalink
Merge branch 'main' into diamondhands/DISABLE-TRADING-FEE-UPDATE
Browse files Browse the repository at this point in the history
  • Loading branch information
lazynina committed Sep 17, 2024
2 parents 716b5de + ce3ff81 commit a19a6a0
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 27 deletions.
2 changes: 1 addition & 1 deletion routes/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var (
IsBlacklisted = []byte{1}
)

const NodeVersion = "4.0.2"
const NodeVersion = "4.0.3"

const (
// RoutePathAPIBase ...
Expand Down
33 changes: 28 additions & 5 deletions routes/hot_feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ import (
// HotnessFeed scoring algorithm knobs.
const (
// Number of blocks per halving for the scoring time decay for the global hot feed.
DefaultHotFeedTimeDecayBlocks uint64 = 72
DefaultHotFeedTimeDecayBlocks uint64 = 43200
// Number of blocks per halving for the scoring time decay for a tag hot feed.
DefaultHotFeedTagTimeDecayBlocks uint64 = 96
DefaultHotFeedTagTimeDecayBlocks uint64 = 43200
// Maximum score amount that any individual PKID can contribute before time decay.
DefaultHotFeedInteractionCap uint64 = 4e12
// Maximum score amount that any individual PKID can contribute before time decay for a particular tag grouping.
DefaultHotFeedTagInteractionCap uint64 = 4e12
// How many iterations of the hot feed calculation until the built-up caches should be reset. (Once per day)
ResetCachesIterationLimit int = 288
// This is how many blocks we consider as part of our ranking. It should be a good deal bigger than
// the time decay blocks.
LookbackWindowBlocks = 7 * 24 * 60 * 60
)

// A single element in the server's HotFeedOrderedList.
Expand Down Expand Up @@ -402,8 +405,7 @@ func (fes *APIServer) UpdateHotFeedOrderedList(
// which is useful for testing purposes.
blockOffsetForTesting := 0

// Grab the last 60 days worth of blocks (25,920 blocks @ 5min/block).
lookbackWindowBlocks := 60 * 24 * 60 / 5
lookbackWindowBlocks := LookbackWindowBlocks
// Check if the most recent blocks that we'll be considering in hot feed computation have been processed.
for _, blockNode := range fes.blockchain.BestChain() {
if blockNode.Height < blockTip.Height-uint32(lookbackWindowBlocks+blockOffsetForTesting) {
Expand Down Expand Up @@ -555,9 +557,30 @@ func (fes *APIServer) PopulateHotnessInfoMap(
// to posts from the specified look-back period without even looking up the post time stamp.
isCreatePost, postHashCreated := CheckTxnForCreatePost(txn)
if isCreatePost {
// We start with the creator's balance in computing the score
timeDecayBlocks := fes.HotFeedTimeDecayBlocks
posterPKIDEntry := utxoView.GetPKIDForPublicKey(txn.PublicKey)
// Finally return the post hash and the txn's hotness score.
//interactionProfile := utxoView.GetProfileEntryForPKID(posterPKIDEntry.PKID)
interactionUserBalance, err := utxoView.GetDeSoBalanceNanosForPublicKey(txn.PublicKey)
if err != nil {
return nil, err
}
// Check for PKID-specifc multipliers for the poster and the interactor.
posterPKIDMultiplier, hasPosterPKIDMultiplier := pkidsToMultipliers[*posterPKIDEntry.PKID]
txnHotnessScore := uint64(interactionUserBalance)
if txnHotnessScore > fes.HotFeedInteractionCap {
txnHotnessScore = fes.HotFeedInteractionCap
}
if hasPosterPKIDMultiplier {
txnHotnessScore = uint64(
posterPKIDMultiplier.PostsMultiplier * float64(txnHotnessScore))
}
hotnessScoreTimeDecayed := uint64(float64(txnHotnessScore) *
math.Pow(0.5, float64(blockAgee)/float64(timeDecayBlocks)))
hotnessInfoMap[*postHashCreated] = &HotnessPostInfo{
PostBlockAge: blockAgee,
HotnessScore: 0,
HotnessScore: hotnessScoreTimeDecayed,
}
continue
}
Expand Down
7 changes: 1 addition & 6 deletions routes/supply.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,9 @@ func (fes *APIServer) UpdateSupplyStats() {
if err != nil {
glog.Errorf("StartSupplyMonitoring: Error getting all locked stake entries")
}
committedTip, _ := fes.TXIndex.TXIndexChain.GetCommittedTip()

for _, lockedStakeEntry := range lockedStakeEntries {
lse := &lib.LockedStakeEntry{}
if err = lse.RawDecodeWithoutMetadata(
uint64(committedTip.Height),
bytes.NewReader(lockedStakeEntry),
); err != nil {
if exists, err := lib.DecodeFromBytes(lse, bytes.NewReader(lockedStakeEntry)); !exists || err != nil {
glog.Errorf("StartSupplyMonitoring: Error decoding locked stake entry: %v", err)
continue
}
Expand Down
11 changes: 1 addition & 10 deletions routes/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -813,16 +813,7 @@ func (fes *APIServer) CompProfileCreation(profilePublicKey []byte, userMetadata
func GetBalanceForPublicKeyUsingUtxoView(
publicKeyBytes []byte, utxoView *lib.UtxoView) (_balance uint64, _err error) {

// Get unspent utxos from the view.
utxoEntriesFound, err := utxoView.GetUnspentUtxoEntrysForPublicKey(publicKeyBytes)
if err != nil {
return 0, fmt.Errorf("UpdateProfile: Problem getting spendable utxos from UtxoView: %v", err)
}
totalBalanceNanos := uint64(0)
for _, utxoEntry := range utxoEntriesFound {
totalBalanceNanos += utxoEntry.AmountNanos
}
return totalBalanceNanos, nil
return utxoView.GetDeSoBalanceNanosForPublicKey(publicKeyBytes)
}

// ExchangeBitcoinRequest ...
Expand Down
12 changes: 10 additions & 2 deletions scripts/tools/clear_ancestral_records.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,23 @@ func main() {
fmt.Printf("Error reading db1 err: %v", err)
return
}
snap, err, _ := lib.NewSnapshot(db, dbDir, lib.SnapshotBlockHeightPeriod, false, false, &lib.DeSoMainnetParams, false, lib.HypersyncDefaultMaxQueueSize)
snap, err, _, _ := lib.NewSnapshot(
db,
uint64(lib.DefaultSnapshotEpochPeriodPoS),
false,
false,
&lib.DeSoMainnetParams,
false,
lib.HypersyncDefaultMaxQueueSize,
nil)
if err != nil {
fmt.Printf("Error reading snap err: %v", err)
return
}
snap.CurrentEpochSnapshotMetadata.SnapshotBlockHeight = 114000
snap.Checksum.ResetChecksum()
for _, prefixByte := range []byte{0, 1, 2} {
prefix := []byte{prefixByte}
prefix := []byte{lib.Prefixes.PrefixHypersyncSnapshotDBPrefix[0], prefixByte}
startKey := prefix
fetchingPrefix := true

Expand Down
2 changes: 1 addition & 1 deletion scripts/tools/compute_db_checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func main() {
fmt.Printf("Error reading db1 err: %v", err)
return
}
snap, err, _ := lib.NewSnapshot(dbSnap, snapshotPeriod, false, false, &lib.DeSoMainnetParams, false, 20, nil)
snap, err, _, _ := lib.NewSnapshot(dbSnap, uint64(snapshotPeriod), false, false, &lib.DeSoMainnetParams, false, 20, nil)
if err != nil {
fmt.Printf("Error reading snap err: %v", err)
return
Expand Down
4 changes: 2 additions & 2 deletions scripts/tools/toolslib/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ func GetBestChainFromBadger(syncedDBHandle *badger.DB, params *lib.DeSoParams) (
}

// Find the tip node with the best node hash.
tipNode := blockIndex[*bestBlockHash]
tipNode, _ := blockIndex.Get(*bestBlockHash)
if tipNode == nil {
return nil, errors.Errorf("GetBestChainFromBadger() bestBlockHash not found in blockIndex")
}

// Walk back from the best node to the genesis block and store them all in bestChain.
bestChain, err := lib.GetBestChain(tipNode, blockIndex)
bestChain, err := lib.GetBestChain(tipNode)
if err != nil {
return nil, errors.Wrap(err, "GetBestChainFromBadger() failed to GetBestChain")
}
Expand Down

0 comments on commit a19a6a0

Please sign in to comment.