Skip to content

Commit

Permalink
chore: update to use only btc header bytes to upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
RafilxTenfen committed Aug 2, 2024
1 parent 4cae2df commit e10c032
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 80 deletions.
75 changes: 15 additions & 60 deletions app/upgrades/signetlaunch/data_btc_headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,94 +3,49 @@ package signetlaunch
const NewBtcHeadersStr = `{
"btc_headers": [
{
"header": "00000020f61eee3b63a380a477a063af32b2bbc97c9ff9f01f2c4225e973988108000000f575c83235984e7dc4afc1f30944c170462e84437ab6f2d52e16878a79e4678bd1914d5fae77031eccf40700",
"hash": "00000086d6b2636cb2a392d45edc4ec544a10024d30141c9adf4bfd9de533b53",
"height": 1,
"work": "77414720"
"header": "00000020f61eee3b63a380a477a063af32b2bbc97c9ff9f01f2c4225e973988108000000f575c83235984e7dc4afc1f30944c170462e84437ab6f2d52e16878a79e4678bd1914d5fae77031eccf40700"
},
{
"header": "00000020533b53ded9bff4adc94101d32400a144c54edc5ed492a3b26c63b2d686000000b38fef50592017cfafbcab88eb3d9cf50b2c801711cad8299495d26df5e54812e7914d5fae77031ecfdd0b00",
"hash": "00000032bb881de703dcc968e8258080c7ed4a2933e3a35888fa0b2f75f36029",
"height": 2,
"work": "77414720"
"header": "00000020533b53ded9bff4adc94101d32400a144c54edc5ed492a3b26c63b2d686000000b38fef50592017cfafbcab88eb3d9cf50b2c801711cad8299495d26df5e54812e7914d5fae77031ecfdd0b00"
},
{
"header": "000000202960f3752f0bfa8858a3e333294aedc7808025e868c9dc03e71d88bb320000007765fcd3d5b4966beb338bba2675dc2cf2ad28d4ad1d83bdb6f286e7e27ac1f807924d5fae77031e81d60b00",
"hash": "000000e8daac2a2e973ecaab46dc948181c638adecf5ae0fd5d3e13aa14364b0",
"height": 3,
"work": "77414720"
"header": "000000202960f3752f0bfa8858a3e333294aedc7808025e868c9dc03e71d88bb320000007765fcd3d5b4966beb338bba2675dc2cf2ad28d4ad1d83bdb6f286e7e27ac1f807924d5fae77031e81d60b00"
},
{
"header": "00000020b06443a13ae1d3d50faef5ecad38c6818194dc46abca3e972e2aacdae800000069a5829097e80fee00ac49a56ea9f82d741a6af84d32b3bc455cf31871e2a8ac27924d5fae77031e9c910500",
"hash": "00000194763f1233e40afd5f6eb2e64abd2e5e158a4139198a224f8a7503d47e",
"height": 4,
"work": "77414720"
"header": "00000020b06443a13ae1d3d50faef5ecad38c6818194dc46abca3e972e2aacdae800000069a5829097e80fee00ac49a56ea9f82d741a6af84d32b3bc455cf31871e2a8ac27924d5fae77031e9c910500"
},
{
"header": "000000207ed403758a4f228a1939418a155e2ebd4ae6b26e5ffd0ae433123f7694010000542e80b609c5bc58af5bdf492e26d4f60cd43a3966c2e063c50444c29b3757a636924d5fae77031ee8601d00",
"hash": "000003776c984edd753b876f0e70d08450f92dd76a768df03d2c42d1880aea5b",
"height": 5,
"work": "77414720"
"header": "000000207ed403758a4f228a1939418a155e2ebd4ae6b26e5ffd0ae433123f7694010000542e80b609c5bc58af5bdf492e26d4f60cd43a3966c2e063c50444c29b3757a636924d5fae77031ee8601d00"
},
{
"header": "000000205bea0a88d1422c3df08d766ad72df95084d0700e6f873b75dd4e986c7703000002b57516d33ed60c2bdd9f93d6d5614083324c837e68e5ba6e04287a7285633585924d5fae77031ed1719600",
"hash": "000001b62ff822d0b1c68e231670eba2cf8d494075f9616447194b370db6f3da",
"height": 6,
"work": "77414720"
"header": "000000205bea0a88d1422c3df08d766ad72df95084d0700e6f873b75dd4e986c7703000002b57516d33ed60c2bdd9f93d6d5614083324c837e68e5ba6e04287a7285633585924d5fae77031ed1719600"
},
{
"header": "00000020daf3b60d374b19476461f97540498dcfa2eb7016238ec6b1d022f82fb60100007a7ae65b53cb988c2ec92d2384996713821d5645ffe61c9acea60da75cd5edfa1a944d5fae77031e9dbb0500",
"hash": "000000b6f018c5b53240616c7868eab7e1338de4200ec25b65a5e1c2f3c57c45",
"height": 7,
"work": "77414720"
"header": "00000020daf3b60d374b19476461f97540498dcfa2eb7016238ec6b1d022f82fb60100007a7ae65b53cb988c2ec92d2384996713821d5645ffe61c9acea60da75cd5edfa1a944d5fae77031e9dbb0500"
},
{
"header": "00000020457cc5f3c2e1a5655bc20e20e48d33e1b7ea68786c614032b5c518f0b6000000541f36942d82c6e7248275ff15c8933487fbe1819c67a9ecc0f4b70bb7e6cf672a944d5fae77031e8f398600",
"hash": "000002213230ed813e42076f753f666244db421b3e36a3a3ba31384feb61eba2",
"height": 8,
"work": "77414720"
"header": "00000020457cc5f3c2e1a5655bc20e20e48d33e1b7ea68786c614032b5c518f0b6000000541f36942d82c6e7248275ff15c8933487fbe1819c67a9ecc0f4b70bb7e6cf672a944d5fae77031e8f398600"
},
{
"header": "00000020a2eb61eb4f3831baa3a3363e1b42db4462663f756f07423e81ed30322102000077224de7dea0f8d0ec22b1d2e2e255f0a987b96fe7200e1a2e6373f48a2f5b7894954d5fae77031e36867e00",
"hash": "000001e163d0a8e294c3406a713ba4363f422f1322a1d6ab6de4e54b51e868a8",
"height": 9,
"work": "77414720"
"header": "00000020a2eb61eb4f3831baa3a3363e1b42db4462663f756f07423e81ed30322102000077224de7dea0f8d0ec22b1d2e2e255f0a987b96fe7200e1a2e6373f48a2f5b7894954d5fae77031e36867e00"
},
{
"header": "00000020a868e8514be5e46dabd6a122132f423f36a43b716a40c394e2a8d063e1010000f4c6c717e99d800c699c25a2006a75a0c5c09f432a936f385e6fce139cdbd1a5e9964d5fae77031e7d026e00",
"hash": "000001418e9af8310ef3644093dbc4a8ad9edb0c9ac80397f3479ad1729d965b",
"height": 10,
"work": "77414720"
"header": "00000020a868e8514be5e46dabd6a122132f423f36a43b716a40c394e2a8d063e1010000f4c6c717e99d800c699c25a2006a75a0c5c09f432a936f385e6fce139cdbd1a5e9964d5fae77031e7d026e00"
},
{
"header": "000000205b969d72d19a47f39703c89a0cdb9eada8c4db934064f30e31f89a8e41010000949eef89068ffc76bf4dca6762e26581d410d0df40edf147d4ffdc6dea404a1512984d5fae77031ee67c1200",
"hash": "0000034cdfe52a76f70f137be5b44dd2d10b305d03a42229767ec5b524d81094",
"height": 11,
"work": "77414720"
"header": "000000205b969d72d19a47f39703c89a0cdb9eada8c4db934064f30e31f89a8e41010000949eef89068ffc76bf4dca6762e26581d410d0df40edf147d4ffdc6dea404a1512984d5fae77031ee67c1200"
},
{
"header": "000000209410d824b5c57e762922a4035d300bd1d24db4e57b130ff7762ae5df4c030000532299955b2dc6bd7c13c267d3c0990fefdf7aec3bcbab5b2c85d0d36316f93644984d5fae77031ecdea1600",
"hash": "000000375d267acf5e788946bd885735d215a98e13eb1b1dcb79403a4549f609",
"height": 12,
"work": "77414720"
"header": "000000209410d824b5c57e762922a4035d300bd1d24db4e57b130ff7762ae5df4c030000532299955b2dc6bd7c13c267d3c0990fefdf7aec3bcbab5b2c85d0d36316f93644984d5fae77031ecdea1600"
},
{
"header": "0000002009f649453a4079cb1d1beb138ea915d2355788bd4689785ecf7a265d3700000010bd26b43a88350e614736674431e62cc7c77dc577d07edd80620a02339d5fab82984d5fae77031efe682400",
"hash": "000000aa98270ecd860f5b0f34eed287b66a24b80738eeb9b5e7a65791ffb935",
"height": 13,
"work": "77414720"
"header": "0000002009f649453a4079cb1d1beb138ea915d2355788bd4689785ecf7a265d3700000010bd26b43a88350e614736674431e62cc7c77dc577d07edd80620a02339d5fab82984d5fae77031efe682400"
},
{
"header": "0000002035b9ff9157a6e7b5b9ee3807b8246ab687d2ee340f5b0f86cd0e2798aa00000028ef48260b3c0d45bbe5321335b05dde8fcb130e063202457884585298b8a5dde4984d5fae77031ec0a08600",
"hash": "00000150de45736bb5158f63a94b9570540d68871eaa8fa03141d16ffb2f1086",
"height": 14,
"work": "77414720"
"header": "0000002035b9ff9157a6e7b5b9ee3807b8246ab687d2ee340f5b0f86cd0e2798aa00000028ef48260b3c0d45bbe5321335b05dde8fcb130e063202457884585298b8a5dde4984d5fae77031ec0a08600"
},
{
"header": "0000002086102ffb6fd14131a08faa1e87680d5470954ba9638f15b56b7345de500100009f423c63aa6d39330082b58808013a85af5a7f338a7a3587f0a85b587665e6174e9a4d5fae77031e79353a00",
"hash": "0000013aadf507653857ebf15a210e31aa7be6d02d1608602a1d4906a08cf528",
"height": 15,
"work": "77414720"
"header": "0000002086102ffb6fd14131a08faa1e87680d5470954ba9638f15b56b7345de500100009f423c63aa6d39330082b58808013a85af5a7f338a7a3587f0a85b587665e6174e9a4d5fae77031e79353a00"
}
]
}`
10 changes: 0 additions & 10 deletions app/upgrades/signetlaunch/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"context"
"errors"
"fmt"
"sort"

store "cosmossdk.io/store/types"
upgradetypes "cosmossdk.io/x/upgrade/types"
Expand Down Expand Up @@ -89,18 +88,9 @@ func insertBtcHeaders(
return errors.New("no headers to insert")
}

// sort by height to make sure it is deterministic
sort.Slice(btcHeaders, func(i, j int) bool {
return btcHeaders[i].Height <= btcHeaders[j].Height
})

headersBytes := make([]bbn.BTCHeaderBytes, len(btcHeaders))
for i, btcHeader := range btcHeaders {
h := btcHeader
if err := h.Validate(); err != nil {
return err
}

headersBytes[i] = *h.Header
}

Expand Down
5 changes: 0 additions & 5 deletions app/upgrades/signetlaunch/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,7 @@ func (s *UpgradeTestSuite) TestUpgrade() {
for i, btcHeaderInserted := range btcHeadersInserted {
btcHeaderInState := allBtcHeaders[oldHeadersLen+i]

s.EqualValues(btcHeaderInserted.Hash.MarshalHex(), btcHeaderInState.Hash.MarshalHex())
s.EqualValues(btcHeaderInserted.Header.MarshalHex(), btcHeaderInState.Header.MarshalHex())
s.EqualValues(btcHeaderInserted.Height, btcHeaderInState.Height)

// TODO: check why work does not match
// s.EqualValues(btcHeaderInserted.Work.String(), btcHeaderInState.Work.String())
}
},
},
Expand Down
7 changes: 2 additions & 5 deletions test/e2e/software_upgrade_e2e_signet_launch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,10 @@ func (s *SoftwareUpgradeSignetLaunchTestSuite) TestUpgradeSignetLaunch() {

// ensure the headers were inserted at the end
for i := 0; i < lenHeadersInserted; i++ {
headerInsertedResp := btcHeadersInserted[i].ToResponse()
headerInserted := btcHeadersInserted[i]
reversedStoredIndex := storedHeadersLen - (oldHeadersStoredLen + i + 1)
headerStoredResp := storedBtcHeadersResp[reversedStoredIndex] // reverse reading

s.EqualValues(headerInsertedResp.HashHex, headerStoredResp.HashHex)
s.EqualValues(headerInsertedResp.HeaderHex, headerStoredResp.HeaderHex)
s.EqualValues(headerInsertedResp.Height, headerStoredResp.Height)
// s.EqualValues(headerInsertedResp.Work.String(), headerStoredResp.Work.String())
s.EqualValues(headerInserted.Header.MarshalHex(), headerStoredResp.HeaderHex)
}
}

0 comments on commit e10c032

Please sign in to comment.