-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add
btc reorg > k
check in end blocker (#518)
- Update `x/btclightclient` hook to also report from which block header is rollingback to `AfterBTCRollBack(ctx context.Context, headerInfo *types.BTCHeaderInfo)` -> `AfterBTCRollBack(ctx context.Context, rollbackFrom, rollbackTo *types.BTCHeaderInfo)` - Implement btc light client hook in `x/btcstaking` to listen `AfterBTCRollBack` and register the largest BTC reorg - Add check in `x/btcstaking` `EndBlocker` that verifies if `largest_reorg > btc_confirmation_depth`
- Loading branch information
1 parent
a58a991
commit dbcc7c4
Showing
33 changed files
with
2,827 additions
and
645 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,106 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
"testing" | ||
"time" | ||
|
||
"github.com/babylonlabs-io/babylon/testutil/datagen" | ||
"github.com/babylonlabs-io/babylon/x/btclightclient/keeper" | ||
"github.com/babylonlabs-io/babylon/x/btclightclient/types" | ||
"github.com/test-go/testify/require" | ||
) | ||
|
||
func TestCheckRollBackInvariants(t *testing.T) { | ||
t.Parallel() | ||
r := rand.New(rand.NewSource(time.Now().Unix())) | ||
|
||
randHeaderFrom := datagen.GenRandomBTCHeaderInfo(r) | ||
randHeaderTo := datagen.GenRandomBTCHeaderInfo(r) | ||
tcs := []struct { | ||
title string | ||
rollbackFrom *types.BTCHeaderInfo | ||
rollbackTo *types.BTCHeaderInfo | ||
expErr error | ||
}{ | ||
{ | ||
"No rollback 'from'", | ||
nil, | ||
datagen.GenRandomBTCHeaderInfo(r), | ||
fmt.Errorf("Call BTC rollback without tip"), | ||
}, | ||
{ | ||
"No rollback 'to'", | ||
datagen.GenRandomBTCHeaderInfo(r), | ||
nil, | ||
fmt.Errorf("Call BTC rollback without rollbackTo"), | ||
}, | ||
{ | ||
"Rollback 'from' height > 'to' height", | ||
&types.BTCHeaderInfo{ | ||
Height: 10, | ||
Hash: randHeaderFrom.Hash, | ||
}, | ||
&types.BTCHeaderInfo{ | ||
Height: 12, | ||
Hash: randHeaderTo.Hash, | ||
}, | ||
fmt.Errorf( | ||
"BTC rollback with rollback 'To' higher or equal than 'From'\n%s\n%s", | ||
fmt.Sprintf("'From' -> %d - %s", 10, randHeaderFrom.Hash.MarshalHex()), | ||
fmt.Sprintf("'To' -> %d - %s", 12, randHeaderTo.Hash.MarshalHex()), | ||
), | ||
}, | ||
{ | ||
"Rollback 'from' height == 'to' height", | ||
&types.BTCHeaderInfo{ | ||
Height: 18, | ||
Hash: randHeaderFrom.Hash, | ||
}, | ||
&types.BTCHeaderInfo{ | ||
Height: 18, | ||
Hash: randHeaderTo.Hash, | ||
}, | ||
fmt.Errorf( | ||
"BTC rollback with rollback 'To' higher or equal than 'From'\n%s\n%s", | ||
fmt.Sprintf("'From' -> %d - %s", 18, randHeaderFrom.Hash.MarshalHex()), | ||
fmt.Sprintf("'To' -> %d - %s", 18, randHeaderTo.Hash.MarshalHex()), | ||
), | ||
}, | ||
{ | ||
"Rollback to correct height", | ||
&types.BTCHeaderInfo{ | ||
Height: 15, | ||
}, | ||
&types.BTCHeaderInfo{ | ||
Height: 12, | ||
}, | ||
nil, | ||
}, | ||
{ | ||
"Rollback to very large height", | ||
&types.BTCHeaderInfo{ | ||
Height: 15000, | ||
}, | ||
&types.BTCHeaderInfo{ | ||
Height: 12, | ||
}, | ||
nil, | ||
}, | ||
} | ||
|
||
for _, tc := range tcs { | ||
t.Run(tc.title, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
actErr := keeper.CheckRollBackInvariants(tc.rollbackFrom, tc.rollbackTo) | ||
if tc.expErr != nil { | ||
require.EqualError(t, actErr, tc.expErr.Error()) | ||
return | ||
} | ||
|
||
require.NoError(t, actErr) | ||
}) | ||
} | ||
} |
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.