This commit is contained in:
Jeffrey Picard 2022-04-11 16:53:35 +00:00
parent d1328fd19a
commit 8be516402b
4 changed files with 390 additions and 402 deletions

View file

@ -26,16 +26,16 @@ import (
const (
// Blochchain height / expiration constants
NOriginalClaimExpirationTime = 262974
NExtendedClaimExpirationTime = 2102400
NExtendedClaimExpirationForkHeight = 400155
NNormalizedNameForkHeight = 539940 // targeting 21 March 2019
NMinTakeoverWorkaroundHeight = 496850
NMaxTakeoverWorkaroundHeight = 658300 // targeting 30 Oct 2019
NWitnessForkHeight = 680770 // targeting 11 Dec 2019
NAllClaimsInMerkleForkHeight = 658310 // targeting 30 Oct 2019
ProportionalDelayFactor = 32
MaxTakeoverDelay = 4032
OriginalClaimExpirationTime = 262974
ExtendedClaimExpirationTime = 2102400
ExtendedClaimExpirationForkHeight = 400155
NormalizedNameForkHeight = 539940 // targeting 21 March 2019
MinTakeoverWorkaroundHeight = 496850
MaxTakeoverWorkaroundHeight = 658300 // targeting 30 Oct 2019
WitnessForkHeight = 680770 // targeting 11 Dec 2019
AllClaimsInMerkleForkHeight = 658310 // targeting 30 Oct 2019
ProportionalDelayFactor = 32
MaxTakeoverDelay = 4032
// Initial size constants
InitialTxCountSize = 1200000
)
@ -440,7 +440,7 @@ func GetProdDB(name string, secondaryPath string) (*ReadOnlyDBColumnFamily, func
cfNames = append(cfNames, cfName)
}
db, err := GetDBColumnFamlies(name, secondaryPath, cfNames)
db, err := GetDBColumnFamilies(name, secondaryPath, cfNames)
cleanup := func() {
db.DB.Close()
@ -455,21 +455,10 @@ func GetProdDB(name string, secondaryPath string) (*ReadOnlyDBColumnFamily, func
return nil, cleanup, err
}
// Wait for the height to be greater than zero
// for {
// ReadDBState(db)
// if db.LastState.Height > 0 {
// logrus.Infof("db height is > 0: %+v\n", db.LastState)
// break
// }
// time.Sleep(time.Millisecond * 100)
// logrus.Infof("Waiting for db height to be > 0: %+v\n", db.LastState)
// }
return db, cleanup, nil
}
func GetDBColumnFamlies(name string, secondayPath string, cfNames []string) (*ReadOnlyDBColumnFamily, error) {
func GetDBColumnFamilies(name string, secondayPath string, cfNames []string) (*ReadOnlyDBColumnFamily, error) {
opts := grocksdb.NewDefaultOptions()
roOpts := grocksdb.NewDefaultReadOptions()
cfOpt := grocksdb.NewDefaultOptions()
@ -591,7 +580,7 @@ func (db *ReadOnlyDBColumnFamily) RunDetectChanges(notifCh chan *internal.Height
log.Debug("DetectChanges:", db.LastState)
lastPrint = time.Now()
}
err := db.DetectChanges(notifCh)
err := db.detectChanges(notifCh)
if err != nil {
log.Infof("Error detecting changes: %#v", err)
}
@ -606,7 +595,7 @@ func (db *ReadOnlyDBColumnFamily) RunDetectChanges(notifCh chan *internal.Height
}
// DetectChanges keep the rocksdb db in sync and handle reorgs
func (db *ReadOnlyDBColumnFamily) DetectChanges(notifCh chan *internal.HeightHash) error {
func (db *ReadOnlyDBColumnFamily) detectChanges(notifCh chan *internal.HeightHash) error {
err := db.DB.TryCatchUpWithPrimary()
if err != nil {
return err

View file

@ -17,12 +17,12 @@ func GetExpirationHeight(lastUpdatedHeight uint32) uint32 {
func GetExpirationHeightFull(lastUpdatedHeight uint32, extended bool) uint32 {
if extended {
return lastUpdatedHeight + NExtendedClaimExpirationTime
return lastUpdatedHeight + ExtendedClaimExpirationTime
}
if lastUpdatedHeight < NExtendedClaimExpirationForkHeight {
return lastUpdatedHeight + NOriginalClaimExpirationTime
if lastUpdatedHeight < ExtendedClaimExpirationForkHeight {
return lastUpdatedHeight + OriginalClaimExpirationTime
}
return lastUpdatedHeight + NExtendedClaimExpirationTime
return lastUpdatedHeight + ExtendedClaimExpirationTime
}
// EnsureHandle is a helper function to ensure that the db has a handle to the given column family.
@ -274,7 +274,7 @@ func (db *ReadOnlyDBColumnFamily) GetActiveAmount(claimHash []byte, txoType uint
}
func (db *ReadOnlyDBColumnFamily) GetEffectiveAmount(claimHash []byte, supportOnly bool) (uint64, error) {
supportAmount, err := db.GetActiveAmount(claimHash, prefixes.ACTIVATED_SUPPORT_TXO_TYPE, db.Height+1)
supportAmount, err := db.GetActiveAmount(claimHash, prefixes.ActivatedSupportTXOType, db.Height+1)
if err != nil {
return 0, err
}
@ -283,7 +283,7 @@ func (db *ReadOnlyDBColumnFamily) GetEffectiveAmount(claimHash []byte, supportOn
return supportAmount, nil
}
activationAmount, err := db.GetActiveAmount(claimHash, prefixes.ACTIVATED_CLAIM_TXO_TYPE, db.Height+1)
activationAmount, err := db.GetActiveAmount(claimHash, prefixes.ActivateClaimTXOType, db.Height+1)
if err != nil {
return 0, err
}
@ -347,9 +347,9 @@ func (db *ReadOnlyDBColumnFamily) GetActivationFull(txNum uint32, postition uint
}
if isSupport {
typ = prefixes.ACTIVATED_SUPPORT_TXO_TYPE
typ = prefixes.ActivatedSupportTXOType
} else {
typ = prefixes.ACTIVATED_CLAIM_TXO_TYPE
typ = prefixes.ActivateClaimTXOType
}
key := prefixes.NewActivationKey(typ, txNum, postition)

View file

@ -606,20 +606,20 @@ func TestGetExpirationHeight(t *testing.T) {
var expHeight uint32 = 0
expHeight = dbpkg.GetExpirationHeight(lastUpdated)
if lastUpdated+dbpkg.NOriginalClaimExpirationTime != expHeight {
t.Errorf("Expected %d, got %d", lastUpdated+dbpkg.NOriginalClaimExpirationTime, expHeight)
if lastUpdated+dbpkg.OriginalClaimExpirationTime != expHeight {
t.Errorf("Expected %d, got %d", lastUpdated+dbpkg.OriginalClaimExpirationTime, expHeight)
}
lastUpdated = dbpkg.NExtendedClaimExpirationForkHeight + 1
lastUpdated = dbpkg.ExtendedClaimExpirationForkHeight + 1
expHeight = dbpkg.GetExpirationHeight(lastUpdated)
if lastUpdated+dbpkg.NExtendedClaimExpirationTime != expHeight {
t.Errorf("Expected %d, got %d", lastUpdated+dbpkg.NExtendedClaimExpirationTime, expHeight)
if lastUpdated+dbpkg.ExtendedClaimExpirationTime != expHeight {
t.Errorf("Expected %d, got %d", lastUpdated+dbpkg.ExtendedClaimExpirationTime, expHeight)
}
lastUpdated = 0
expHeight = dbpkg.GetExpirationHeightFull(lastUpdated, true)
if lastUpdated+dbpkg.NExtendedClaimExpirationTime != expHeight {
t.Errorf("Expected %d, got %d", lastUpdated+dbpkg.NExtendedClaimExpirationTime, expHeight)
if lastUpdated+dbpkg.ExtendedClaimExpirationTime != expHeight {
t.Errorf("Expected %d, got %d", lastUpdated+dbpkg.ExtendedClaimExpirationTime, expHeight)
}
}

File diff suppressed because it is too large Load diff