-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: query fp before register #226
Changes from 5 commits
a56d903
cb19ed8
b6d4cd9
49fca83
9ece93a
8fe63b1
ccd4cfb
08a343c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -349,9 +349,30 @@ func (app *FinalityProviderApp) CreateFinalityProvider( | |
return nil, fmt.Errorf("failed to create proof-of-possession of the finality-provider: %w", err) | ||
} | ||
|
||
// TODO: query consumer chain to check if the fp is already registered | ||
// Query the consumer chain to check if the fp is already registered | ||
// if true, update db with the fp info from the consumer chain | ||
// otherwise, proceed registration | ||
resp, err := app.cc.QueryFinalityProvider(eotsPk.MustToBTCPK()) | ||
if err != nil { | ||
if !strings.Contains(err.Error(), "the finality provider is not found") { | ||
return nil, fmt.Errorf("err getting finality provider: %w", err) | ||
} | ||
} | ||
if resp != nil { | ||
if err := app.updateFpFromResponse(eotsPk.MustToBTCPK(), resp.FinalityProvider); err != nil { | ||
return nil, err | ||
} | ||
|
||
// get updated fp from db | ||
storedFp, err := app.fps.GetFinalityProvider(eotsPk.MustToBTCPK()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &CreateFinalityProviderResult{ | ||
FpInfo: storedFp.ToFinalityProviderInfo(), | ||
}, nil | ||
} | ||
|
||
// 3. register the finality provider on the consumer chain | ||
request := &CreateFinalityProviderRequest{ | ||
|
@@ -558,3 +579,37 @@ func (app *FinalityProviderApp) getFpPrivKey(fpPk []byte) (*btcec.PrivateKey, er | |
|
||
return record.PrivKey, nil | ||
} | ||
|
||
func (app *FinalityProviderApp) updateFpFromResponse(btcPk *btcec.PublicKey, fp *bstypes.FinalityProviderResponse) error { | ||
if err := app.fps.SetFpDescription(btcPk, fp.Description, fp.Commission); err != nil { | ||
return err | ||
} | ||
|
||
if err := app.fps.SetFpLastVotedHeight(btcPk, uint64(fp.HighestVotedHeight)); err != nil { | ||
return err | ||
} | ||
|
||
power, err := app.cc.QueryFinalityProviderVotingPower(btcPk, fp.Height) | ||
if err != nil { | ||
return fmt.Errorf("failed to query voting power for finality provider %v: %w", | ||
btcPk, err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's print the hex string of the public key |
||
} | ||
|
||
var status proto.FinalityProviderStatus | ||
switch { | ||
case power > 0: | ||
status = proto.FinalityProviderStatus_ACTIVE | ||
case fp.SlashedBtcHeight > 0: | ||
status = proto.FinalityProviderStatus_SLASHED | ||
case fp.Jailed: | ||
status = proto.FinalityProviderStatus_JAILED | ||
default: | ||
status = proto.FinalityProviderStatus_INACTIVE | ||
} | ||
|
||
if err := app.fps.SetFpStatus(btcPk, status); err != nil { | ||
return fmt.Errorf("failed to update status for finality provider %v: %w", btcPk, err) | ||
} | ||
|
||
return nil | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have a test case where the fp is already registered but not in db, so calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's have a log here to indicate the registration is already done