Skip to content
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

feat(ARCO-115): Reorg Support #611

Merged
merged 36 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
fdb3d5c
feat: initial template for the feature
kuba-4chain Sep 12, 2024
49bd2fb
feat: improve logic of publishing mined txs to metamorph, unlink upse…
kuba-4chain Oct 8, 2024
25b7518
feat: improved way of transactions publishing to metamorph, store met…
kuba-4chain Oct 9, 2024
2c39e41
feat: improve logs
kuba-4chain Oct 9, 2024
2a380ed
feat: integration test for reorg - stale blocks
kuba-4chain Oct 10, 2024
bdebf8d
feat: integration test for reorg with edge cases
kuba-4chain Oct 11, 2024
973f885
feat: integration test refactored and documented
kuba-4chain Oct 11, 2024
f87253b
feat: add new status MINED_IN_STALE_BLOCK and handle logic for that s…
kuba-4chain Oct 11, 2024
a9a42bb
chore: fix proto indentation
kuba-4chain Oct 11, 2024
73d7962
chore: comments removed
kuba-4chain Oct 11, 2024
f8c4ff3
chore: fix test structure after refactor
kuba-4chain Oct 11, 2024
d8ee0d9
feat: fix wrong condition
kuba-4chain Oct 14, 2024
6e1fd9c
feat: improve error types
kuba-4chain Oct 16, 2024
1cba622
Reorg Support: Handling of orphaned blocks (#617)
kuba-4chain Nov 6, 2024
0e84f19
feat(ARCO-199): update files after rebase
Nov 6, 2024
7744982
chore(ARCO-199): cosmetic fixes
kuba-4chain Nov 6, 2024
de2336a
chore(ARCO-199): satisfy linter and generate mocks
kuba-4chain Nov 6, 2024
b64a991
chore(ARCO-199): linter errors again
kuba-4chain Nov 6, 2024
e96c972
feat(ARCO-199): remove status from GetBlockByHeight
kuba-4chain Nov 6, 2024
777979e
feat(ARCO-199): fix e2e tests
kuba-4chain Nov 7, 2024
a72a80e
feat(ARCO-199): create a clone of blocktx store for UnitOfWork purposes
kuba-4chain Nov 7, 2024
c8c8fbd
chore(ARCO-199): rename mock in tests
kuba-4chain Nov 7, 2024
734b60a
feat(ARCO-199): improve UnitOfWork in blocktx store
kuba-4chain Nov 7, 2024
d76bb00
feat(ARCO-199): remove publishing to metamorh for incoming STALE blocks
kuba-4chain Nov 7, 2024
2d085c8
chore(ARCO-199): ignore a gosec warning intentionally
kuba-4chain Nov 8, 2024
f591c12
feat(reorg): simplification (#651)
kuba-4chain Nov 20, 2024
db42869
chore: removing unused variables, using different testing methods
kuba-4chain Nov 20, 2024
255f28a
feat: adapt to new error traces
kuba-4chain Nov 22, 2024
16f5722
refactor: move blockhash higher
kuba-4chain Nov 28, 2024
ed0e378
feat: checking for processed blocks in blocktx store queries and smal…
kuba-4chain Dec 3, 2024
2632168
feat: add hash to blockmessage
kuba-4chain Dec 3, 2024
1b11129
refactor(reorg-support): improved integration test (#689)
kuba-4chain Dec 4, 2024
8600b2d
fix: fix tests
kuba-4chain Dec 4, 2024
bd1fb81
feat: add status MINED_IN_STALE_BLOCK to callbacker
kuba-4chain Dec 4, 2024
6689e3a
feat(ARCO-180): reorg e2e tests (#666)
kuba-4chain Dec 5, 2024
86d2ec6
feat: documentation for reorg (#682)
kuba-4chain Dec 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions cmd/arc/services/metamorph.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func StartMetamorph(logger *slog.Logger, arcConfig *config.ArcConfig, cacheStore
metamorphStore store.MetamorphStore
peerHandler *metamorph.PeerHandler
pm metamorph.PeerManager
statusMessageCh chan *metamorph.PeerTxMessage
statusMessageCh chan *metamorph.TxStatusMessage
mqClient metamorph.MessageQueueClient
processor *metamorph.Processor
server *metamorph.Server
Expand Down Expand Up @@ -196,7 +196,6 @@ func StartMetamorph(logger *slog.Logger, arcConfig *config.ArcConfig, cacheStore

server, err = metamorph.NewServer(arcConfig.PrometheusEndpoint, arcConfig.GrpcMessageSize, logger,
metamorphStore, processor, arcConfig.Tracing, optsServer...)

if err != nil {
stopFn()
return nil, fmt.Errorf("create GRPCServer failed: %v", err)
Expand Down Expand Up @@ -273,15 +272,15 @@ func NewMetamorphStore(dbConfig *config.DbConfig, tracingConfig *config.TracingC
return s, err
}

func initPeerManager(logger *slog.Logger, s store.MetamorphStore, arcConfig *config.ArcConfig) (p2p.PeerManagerI, *metamorph.PeerHandler, chan *metamorph.PeerTxMessage, error) {
func initPeerManager(logger *slog.Logger, s store.MetamorphStore, arcConfig *config.ArcConfig) (p2p.PeerManagerI, *metamorph.PeerHandler, chan *metamorph.TxStatusMessage, error) {
network, err := config.GetNetwork(arcConfig.Network)
if err != nil {
return nil, nil, nil, fmt.Errorf("failed to get network: %v", err)
}

logger.Info("Assuming bitcoin network", "network", network)

messageCh := make(chan *metamorph.PeerTxMessage, 10000)
messageCh := make(chan *metamorph.TxStatusMessage, 10000)
var pmOpts []p2p.PeerManagerOptions
if arcConfig.Metamorph.MonitorPeers {
pmOpts = append(pmOpts, p2p.WithRestartUnhealthyPeers())
Expand Down
1 change: 1 addition & 0 deletions internal/blocktx/blockchain_communication/block_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

// BlockMessage only stores the transaction IDs of the block, not the full transactions
type BlockMessage struct {
Hash *chainhash.Hash
Header *wire.BlockHeader
Height uint64
TransactionHashes []*chainhash.Hash
Expand Down
2 changes: 2 additions & 0 deletions internal/blocktx/blockchain_communication/p2p/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ func init() {
}

blockMessage.Size = uint64(bytesRead)
blockHash := blockMessage.Header.BlockHash()
blockMessage.Hash = &blockHash

return bytesRead, blockMessage, nil, nil
})
Expand Down
270 changes: 136 additions & 134 deletions internal/blocktx/blocktx_api/blocktx_api.pb.go

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions internal/blocktx/blocktx_api/blocktx_api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ message Block {
bytes previous_hash = 2; // Little endian
bytes merkle_root = 3; // Little endian
uint64 height = 4;
bool orphaned = 5;
bool processed = 6;
Status status = 7;
string chainwork = 8;
bool processed = 5;
Status status = 6;
string chainwork = 7;
}

// swagger:model Transactions
Expand All @@ -65,6 +64,7 @@ message TransactionBlock {
uint64 block_height = 2;
bytes transaction_hash = 3; // Little endian
string merklePath = 4;
Status block_status = 5;
}

message TransactionBlocks {
Expand Down
2 changes: 1 addition & 1 deletion internal/blocktx/blocktx_api/blocktx_api_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- blockid: 1002
txid: 1000003
merkle_path: merkle-path-3
inserted_at: 2023-12-10 14:00:00
- blockid: 1999 # the same tx also in stale block
txid: 1000003
merkle_path: merkle-path-999
inserted_at: 2023-12-10 14:00:00
- blockid: 1999 # the same tx also in stale block
txid: 1000001
merkle_path: merkle-path-999
inserted_at: 2023-12-10 14:00:00
- blockid: 1004
txid: 1000005
merkle_path: merkle-path-5
inserted_at: 2023-12-10 14:00:00
Original file line number Diff line number Diff line change
@@ -1,47 +1,72 @@
- inserted_at: 2023-12-15 14:00:00
id: 0
id: 1001
hash: 0xf97e20396f02ab990ed31b9aec70c240f48b7e5ea239aa050000000000000000
prevhash: 0xb71ab063c5f96cad71cdc59dcc94182a20a69cbd7eed2d070000000000000000
merkleroot: 0x7f4019eb006f5333cce752df387fa8443035c22291eb771ee5b16a02b81c8483
height: 822014
processed_at: 2023-12-15 14:10:00
size: 86840000
tx_count: 23477
orphanedyn: false
status: 10
is_longest: true
chainwork: '62209952899966'
- inserted_at: 2023-12-15 14:30:00
id: 1
id: 1002
hash: 0xc9b4e1e4dcf9188416027511671b9346be8ef93c0ddf59060000000000000000
prevhash: 0x67708796ef57464ed9eaf2a663d3da32372e4c2fb65558020000000000000000
merkleroot: 0x7382df1b717287ab87e5e3e25759697c4c45eea428f701cdd0c77ad3fc707257
height: 822015
processed_at: 2023-12-15 14:30:00
size: 20160000
tx_count: 6523
orphanedyn: false
status: 10
is_longest: true
chainwork: '62209952899966'
- inserted_at: 2023-12-15 14:30:00
id: 1999
hash: 0x82471bbf045ab13825a245b37de71d77ec12513b37e2524ec11551d18c19f7c3
prevhash: 0x67708796ef57464ed9eaf2a663d3da32372e4c2fb65558020000000000000000
merkleroot: 0x7382df1b717287ab87e5e3e25759697c4c45eea428f701cdd0c77ad3fc707257
height: 822015
processed_at: 2023-12-15 14:30:00
size: 20160000
tx_count: 6523
status: 20 # STALE - competing block
is_longest: false
chainwork: '62209952899966'
- inserted_at: 2023-12-15 14:40:00
id: 2
id: 1003
hash: 0xe1df1273e6e7270f96b508545d7aa80aebda7d758dc82e080000000000000000
prevhash: 0xc9b4e1e4dcf9188416027511671b9346be8ef93c0ddf59060000000000000000
merkleroot: 0x4b58b0402a84012269b124f78c91a78a814eb3c9caa03f1df1d33172b23082d1
height: 822016
processed_at: 2023-12-15 14:40:00
size: 299650000
tx_count: 62162
orphanedyn: false
status: 10
is_longest: true
chainwork: '62209952899966'
- inserted_at: 2023-12-15 14:50:00
id: 3
id: 1004
hash: 0x76404890880cb36ce68100abb05b3a958e17c0ed274d5c0a0000000000000000
prevhash: 0x5696fc6e504b6aa2ae5d9c46b9418192dc61bd1b2e3364030000000000000000
prevhash: 0xe1df1273e6e7270f96b508545d7aa80aebda7d758dc82e080000000000000000
merkleroot: 0xc458aa382364e216c9c0533175ec8579a544c750ca181b18296e784d1dc53085
height: 822017
size: 8630000
processed_at: 2023-12-15 14:40:00
tx_count: 36724
orphanedyn: false
status: 10
is_longest: true
chainwork: '62209952899966'
- inserted_at: 2023-12-15 14:50:00
id: 10052
hash: 0x000000000000000003b15d668b54c4b91ae81a86298ee209d9f39fd7a769bcde
prevhash: 0x76404890880cb36ce68100abb05b3a958e17c0ed274d5c0a0000000000000000
merkleroot: 0xde0753d9ce6f92e340843cbfdd11e58beff8c578956ecdec4c461b018a26b8a9
height: 822018
size: 8630000
processed_at: 2023-12-15 14:40:00
tx_count: 36724
status: 30 # ORPHANED
is_longest: false
chainwork: '62209952899966'
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
- id: 1000001
hash: 0xcd3d2f97dfc0cdb6a07ec4b72df5e1794c9553ff2f62d90ed4add047e8088853
inserted_at: 2023-12-10 14:00:00
is_registered: true
- id: 1000002
hash: 0x21132d32cb5411c058bb4391f24f6a36ed9b810df851d0e36cac514fd03d6b4e
inserted_at: 2023-12-10 14:00:00
is_registered: false
- id: 1000003
hash: 0xb16cea53fc823e146fbb9ae4ad3124f7c273f30562585ad6e4831495d609f430
inserted_at: 2023-12-10 14:00:00
is_registered: true
- id: 1000004
hash: 0x2ff4430eb883c6f6c0640a5d716b2d107bbc0efa5aeaa237aec796d4686b0a8f
inserted_at: 2023-12-10 14:00:00
is_registered: true
- id: 1000005
hash: 0xece2b7e40d98749c03c551b783420d6e3fdc3c958244bbf275437839585829a6
inserted_at: 2023-12-10 14:00:00
is_registered: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
- blockid: 1002
txid: 1000001
merkle_path: merkle-path-1
inserted_at: 2023-12-10 14:00:00
- blockid: 1002
txid: 1000003
merkle_path: merkle-path-3
inserted_at: 2023-12-10 14:00:00
- blockid: 1004
txid: 1000003
merkle_path: merkle-path-3-competing
inserted_at: 2023-12-10 14:00:00
- blockid: 1003
txid: 1000004
merkle_path: merkle-path-4
inserted_at: 2023-12-10 14:00:00
- blockid: 1006
txid: 1000005
merkle_path: merkle-path-5
inserted_at: 2023-12-10 14:00:00
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
- inserted_at: 2023-12-15 14:00:00
id: 1001
hash: 0xf97e20396f02ab990ed31b9aec70c240f48b7e5ea239aa050000000000000000
prevhash: 0xb71ab063c5f96cad71cdc59dcc94182a20a69cbd7eed2d070000000000000000
merkleroot: 0x7f4019eb006f5333cce752df387fa8443035c22291eb771ee5b16a02b81c8483
height: 822014
processed_at: 2023-12-15 14:10:00
size: 86840000
tx_count: 23477
status: 10
is_longest: true
chainwork: '62209952899966'

- inserted_at: 2023-12-15 14:30:00
id: 1002
hash: 0x82471bbf045ab13825a245b37de71d77ec12513b37e2524ec11551d18c19f7c3
prevhash: 0x67708796ef57464ed9eaf2a663d3da32372e4c2fb65558020000000000000000
merkleroot: 0x7382df1b717287ab87e5e3e25759697c4c45eea428f701cdd0c77ad3fc707257
height: 822015
processed_at: 2023-12-15 14:30:00
size: 20160000
tx_count: 6523
status: 10
is_longest: true
chainwork: '62209952899966'
- inserted_at: 2023-12-15 14:30:00
id: 1003
hash: 0x032c3688bc7536b2d787f3a196b1145a09bf33183cd1448ff6b1a9dfbb022db8
prevhash: 0x82471bbf045ab13825a245b37de71d77ec12513b37e2524ec11551d18c19f7c3
merkleroot: 0x7382df1b717287ab87e5e3e25759697c4c45eea428f701cdd0c77ad3fc707257
height: 822016
processed_at: 2023-12-15 14:30:00
size: 20160000
tx_count: 6523
status: 10
is_longest: true
chainwork: '12301577519373468'

- inserted_at: 2023-12-15 14:30:00
id: 1004
hash: 0xc9b4e1e4dcf9188416027511671b9346be8ef93c0ddf59060000000000000000
prevhash: 0x67708796ef57464ed9eaf2a663d3da32372e4c2fb65558020000000000000000
merkleroot: 0x7382df1b717287ab87e5e3e25759697c4c45eea428f701cdd0c77ad3fc707257
height: 822015
processed_at: 2023-12-15 14:30:00
size: 20160000
tx_count: 6523
status: 20 # STALE
is_longest: false
chainwork: '62209952899966'
- inserted_at: 2023-12-15 14:40:00
id: 1005
hash: 0xe1df1273e6e7270f96b508545d7aa80aebda7d758dc82e080000000000000000
prevhash: 0xc9b4e1e4dcf9188416027511671b9346be8ef93c0ddf59060000000000000000
merkleroot: 0x4b58b0402a84012269b124f78c91a78a814eb3c9caa03f1df1d33172b23082d1
height: 822016
processed_at: 2023-12-15 14:40:00
size: 299650000
tx_count: 62162
status: 20 # STALE
is_longest: false
chainwork: '62209952899966'
- inserted_at: 2023-12-15 14:50:00
id: 1006
hash: 0x76404890880cb36ce68100abb05b3a958e17c0ed274d5c0a0000000000000000
prevhash: 0xe1df1273e6e7270f96b508545d7aa80aebda7d758dc82e080000000000000000
merkleroot: 0xc458aa382364e216c9c0533175ec8579a544c750ca181b18296e784d1dc53085
height: 822017
size: 8630000
processed_at: 2023-12-15 14:40:00
tx_count: 36724
status: 20 # STALE
is_longest: false
chainwork: '62209952899966'

- inserted_at: 2023-12-15 14:50:00
id: 1007
hash: 0x000000000000000003b15d668b54c4b91ae81a86298ee209d9f39fd7a769bcde
prevhash: 0x76404890880cb36ce68100abb05b3a958e17c0ed274d5c0a0000000000000000
merkleroot: 0xde0753d9ce6f92e340843cbfdd11e58beff8c578956ecdec4c461b018a26b8a9
height: 822018
size: 8630000
processed_at: 2023-12-15 14:40:00
tx_count: 36724
status: 30 # ORPHANED
is_longest: false
chainwork: '62209952899966'
- inserted_at: 2023-12-15 14:50:00
id: 1008
hash: 0x00000000000000000364332e1bbd61dc928141b9469c5daea26a4b506efc9656
prevhash: 0x000000000000000003b15d668b54c4b91ae81a86298ee209d9f39fd7a769bcde
merkleroot: 0x51f33784f6d54f1d6414fa4d8b8d6904215cb16a3fa0a8b1fe02e456a90544d4
height: 822019
size: 8630000
processed_at: 2023-12-15 14:40:00
tx_count: 36724
status: 30 # ORPHANED
is_longest: false
chainwork: '62209952899966'
- inserted_at: 2023-12-15 14:50:00
id: 1009
hash: 0x00000000000000000a5c4d27edc0178e953a5bb0ab0081e66cb30c8890484076
prevhash: 0x00000000000000000364332e1bbd61dc928141b9469c5daea26a4b506efc9656
merkleroot: 0xc458aa382364e216c9c0533175ec8579a544c750ca181b18296e784d1dc53085
height: 822020
size: 8630000
processed_at: 2023-12-15 14:40:00
tx_count: 36724
status: 30 # ORPHANED
is_longest: false
chainwork: '12301481384759134'

# gap

- inserted_at: 2023-12-15 14:50:00
id: 1010
hash: 0x0000000000000000059d6add76e3ddb8ec4f5ffd6efecd4c8b8c577bd32aed6c
prevhash: 0xd46bf0a189927b62c8ff785d393a545093ca01af159aed771a8d94749f06c060
merkleroot: 0xda71199f8ed9203d8a765595e6c030a22e5ed8330b1abb467a82c97d7d21d512
height: 822022
size: 8630000
processed_at: 2023-12-15 14:40:00
tx_count: 36724
status: 30 # ORPHANED
is_longest: false
chainwork: '62209952899966'
- inserted_at: 2023-12-15 14:50:00
id: 1011
hash: 0x0000000000000000082131979a4e25a5101912a5f8461e18f306d23e158161cd
prevhash: 0x0000000000000000059d6add76e3ddb8ec4f5ffd6efecd4c8b8c577bd32aed6c
merkleroot: 0x8e3177a33d6a87785b7104f20ca345e1713ae11ec2723a41028efddabebb861b
height: 822023
size: 8630000
processed_at: 2023-12-15 14:40:00
tx_count: 36724
status: 30 # ORPHANED
is_longest: false
chainwork: '12301481384759134'
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
- id: 1000001
hash: 0xcd3d2f97dfc0cdb6a07ec4b72df5e1794c9553ff2f62d90ed4add047e8088853
inserted_at: 2023-12-10 14:00:00
is_registered: true
- id: 1000002
hash: 0x21132d32cb5411c058bb4391f24f6a36ed9b810df851d0e36cac514fd03d6b4e
inserted_at: 2023-12-10 14:00:00
is_registered: false
- id: 1000003
hash: 0xb16cea53fc823e146fbb9ae4ad3124f7c273f30562585ad6e4831495d609f430
inserted_at: 2023-12-10 14:00:00
is_registered: true
- id: 1000004
hash: 0x2ff4430eb883c6f6c0640a5d716b2d107bbc0efa5aeaa237aec796d4686b0a8f
inserted_at: 2023-12-10 14:00:00
is_registered: true
- id: 1000005
hash: 0xece2b7e40d98749c03c551b783420d6e3fdc3c958244bbf275437839585829a6
inserted_at: 2023-12-10 14:00:00
is_registered: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- blockid: 1002
txid: 1000003
merkle_path: merkle-path-3
inserted_at: 2023-12-10 14:00:00
Loading
Loading