-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: return IsEligibleForTransition in delegation (#139)
* feat: return IsEligibleForTransition in delegation
- Loading branch information
1 parent
ac145a0
commit 4ba5e0c
Showing
21 changed files
with
250 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package indexerdbclient | ||
|
||
import ( | ||
"context" | ||
|
||
indexerdbmodel "github.com/babylonlabs-io/staking-api-service/internal/indexer/db/model" | ||
"go.mongodb.org/mongo-driver/bson" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
) | ||
|
||
func (db *IndexerDatabase) GetLastProcessedBbnHeight(ctx context.Context) (uint64, error) { | ||
// If not in context, query from database | ||
var result indexerdbmodel.LastProcessedHeight | ||
err := db.Client.Database(db.DbName).Collection( | ||
indexerdbmodel.LastProcessedHeightCollection, | ||
).FindOne(ctx, bson.M{}).Decode(&result) | ||
if err == mongo.ErrNoDocuments { | ||
// If no document exists, return 0 | ||
return 0, nil | ||
} | ||
if err != nil { | ||
return 0, err | ||
} | ||
return result.Height, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package indexerdbmodel | ||
|
||
type LastProcessedHeight struct { | ||
Height uint64 `bson:"height"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package config | ||
|
||
import "errors" | ||
|
||
// DelegationTransitionConfig represents the transition cutoff height for | ||
// the phase-1 delegation to phase-2. | ||
// A delegation can transition to phase-2 if either: | ||
// 1. The delegation's BTC staking height is less than EligibleBeforeBtcHeight, or | ||
// 2. The current BBN height is greater than AllowListExpirationHeight | ||
// (allowing all delegations to transition) | ||
type DelegationTransitionConfig struct { | ||
EligibleBeforeBtcHeight uint64 `mapstructure:"eligible_before_btc_height"` | ||
AllowListExpirationHeight uint64 `mapstructure:"allow_list_expiration_height"` | ||
} | ||
|
||
func (cfg *DelegationTransitionConfig) Validate() error { | ||
if cfg.EligibleBeforeBtcHeight == 0 { | ||
return errors.New("before_btc_height cannot be 0") | ||
} | ||
|
||
if cfg.AllowListExpirationHeight == 0 { | ||
return errors.New("allow_list_expiration_height cannot be 0") | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.