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: re-broadcast stale txs #739

Draft
wants to merge 30 commits into
base: feat/reactivate-reorg-support
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2f373eb
refactor(ARCO-312): Do not store Merkle paths
boecklim Jan 3, 2025
d2e01e4
refactor(ARCO-312): Add height to log
boecklim Jan 6, 2025
c214259
refactor(ARCO-312): Increase batch size
boecklim Jan 6, 2025
09e26b0
refactor(ARCO-312): Fix test
boecklim Jan 6, 2025
fbd4475
refactor(ARCO-312): Rm comment
boecklim Jan 6, 2025
37578db
refactor(ARCO-312): Processing speed of block
boecklim Jan 6, 2025
ff692e4
refactor(ARCO-312): Remove unused indices
boecklim Jan 7, 2025
7c01ab2
refactor(ARCO-312): Reduce code duplication
boecklim Jan 7, 2025
4651939
refactor(ARCO-312): Make lint
boecklim Jan 7, 2025
c61468a
refactor(ARCO-312): Remove unused inserted_at field in block_transact…
boecklim Jan 7, 2025
e46d00a
refactor(ARCO-312): Store transactions in parallel
boecklim Jan 7, 2025
4cfcb13
refactor(ARCO-312): Show progress for steps
boecklim Jan 7, 2025
fd10a67
refactor(ARCO-312): Check correctness of Merkle paths
boecklim Jan 9, 2025
5361135
refactor(ARCO-312): revert temporarily stop reorg support handling to…
boecklim Jan 7, 2025
cfb9928
refactor(ARCO-312): Assigning block status depending on setting
boecklim Jan 7, 2025
2747a3c
refactor(ARCO-312): Fix tests
boecklim Jan 7, 2025
aa720f7
refactor(ARCO-312): Remove unused fixture
boecklim Jan 7, 2025
0b399e7
refactor(ARCO-312): Revert comments
boecklim Jan 7, 2025
fb953fc
refactor(ARCO-312): Capitalize error log
boecklim Jan 9, 2025
bdb3e9e
refactor(ARCO-312): Use hex string for map key
boecklim Jan 9, 2025
ac19675
refactor(ARCO-312): Fix comment
boecklim Jan 8, 2025
cbdcf74
refactor(ARCO-312): Fix integration tests
boecklim Jan 9, 2025
0770104
refactor(ARCO-312): Refactor opts
boecklim Jan 9, 2025
e97e4a5
refactor(ARCO-312): Setting which decides whether a received block is…
boecklim Jan 9, 2025
471f1f7
feat: re-broadcast stale txs
kuba-4chain Nov 29, 2024
1a8e526
feat: documentation update
kuba-4chain Dec 5, 2024
e589813
feat: include height range in getting the chain tip
kuba-4chain Dec 5, 2024
a6c396d
feat: update e2e test
kuba-4chain Dec 23, 2024
1cb3d84
fix: uncomment blockhash
kuba-4chain Dec 23, 2024
4c79510
fix: Fix after rebase
boecklim Jan 9, 2025
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
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ build_docker:

.PHONY: run
run:
docker compose down --remove-orphans
docker compose down -v --remove-orphans
docker compose up --build blocktx callbacker metamorph api

.PHONY: run_e2e_tests
run_e2e_tests:
docker compose down --remove-orphans
docker compose down -v --remove-orphans
docker compose up --build blocktx callbacker metamorph api tests --scale blocktx=4 --scale metamorph=2 --exit-code-from tests
docker compose down

.PHONY: run_e2e_tests_with_tracing
run_e2e_tests_with_tracing:
docker compose down --remove-orphans
docker compose down -v --remove-orphans
ARC_TRACING_ENABLED=TRUE docker compose up --build blocktx callbacker metamorph api tests jaeger --scale blocktx=4 --scale metamorph=2 --no-attach jaeger

.PHONY: test
Expand Down
4 changes: 3 additions & 1 deletion cmd/arc/services/blocktx.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import (

"go.opentelemetry.io/otel/attribute"

"github.com/libsv/go-p2p"

"github.com/bitcoin-sv/arc/internal/grpc_opts"
"github.com/bitcoin-sv/arc/internal/message_queue/nats/client/nats_core"
"github.com/bitcoin-sv/arc/internal/message_queue/nats/client/nats_jetstream"
"github.com/bitcoin-sv/arc/internal/message_queue/nats/nats_connection"
"github.com/bitcoin-sv/arc/internal/tracing"
"github.com/libsv/go-p2p"

"github.com/bitcoin-sv/arc/config"
"github.com/bitcoin-sv/arc/internal/blocktx"
Expand Down Expand Up @@ -127,6 +128,7 @@ func StartBlockTx(logger *slog.Logger, arcConfig *config.ArcConfig) (func(), err
blocktx.WithRegisterTxsInterval(btxConfig.RegisterTxsInterval),
blocktx.WithMessageQueueClient(mqClient),
blocktx.WithMaxBlockProcessingDuration(btxConfig.MaxBlockProcessingDuration),
blocktx.WithIncomingIsLongest(btxConfig.IncomingIsLongest),
)

blockRequestCh := make(chan blocktx.BlockRequest, blockProcessingBuffer)
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ type BlocktxConfig struct {
MaxAllowedBlockHeightMismatch int `mapstructure:"maxAllowedBlockHeightMismatch"`
MessageQueue *MessageQueueConfig `mapstructure:"mq"`
P2pReadBufferSize int `mapstructure:"p2pReadBufferSize"`
IncomingIsLongest bool `mapstructure:"incomingIsLongest"`
}

type DbConfig struct {
Expand Down
1 change: 1 addition & 0 deletions config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func getBlocktxConfig() *BlocktxConfig {
MaxBlockProcessingDuration: 5 * time.Minute,
MessageQueue: &MessageQueueConfig{},
P2pReadBufferSize: 8 * 1024 * 1024,
IncomingIsLongest: false,
}
}

Expand Down
1 change: 1 addition & 0 deletions config/example_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ blocktx:
registerTxsInterval: 10s # time interval to read from the channel registered transactions
maxBlockProcessingDuration: 5m # maximum time a blocktx can spend on processing a block before unlocking it to be requested again
monitorPeers: false # if enabled, peers which do not receive alive signal from nodes will be restarted
incomingIsLongest: false # whether each new block received is considered to be from the longest blockchain. If there are a lot of block gaps in blocktx database it is advisable to set this to true
fillGaps:
enabled: true
interval: 15m # time interval to check and fill gaps in processed blocks
Expand Down
7 changes: 4 additions & 3 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ stateDiagram-v2
ACCEPTED_BY_NETWORK --> SEEN_ON_NETWORK: ARC has received Transaction ID\n announcement from another peer
ACCEPTED_BY_NETWORK --> SEEN_IN_ORPHAN_MEMPOOL: Peer has sent a 'missing inputs' message
SEEN_IN_ORPHAN_MEMPOOL --> SEEN_ON_NETWORK: All parent transactions\n have been received by peer
SEEN_ON_NETWORK --> MINED: Transaction ID was included in a BLOCK message
SEEN_ON_NETWORK --> DOUBLE_SPEND_ATTEMPTED: A competing transactions entered the mempool
DOUBLE_SPEND_ATTEMPTED --> MINED: This transaction was accepted and mined
DOUBLE_SPEND_ATTEMPTED --> REJECTED: This transaction was rejected in favor\n of one of the competing transactions
MINED --> MINED_IN_STALE_BLOCK: This transaction was mined in a block that became stale after reorg
DOUBLE_SPEND_ATTEMPTED --> MINED: This transaction was accepted and mined
SEEN_ON_NETWORK --> MINED: Transaction ID was included in a BLOCK message
MINED_IN_STALE_BLOCK --> SEEN_ON_NETWORK: Transaction gets re-broadcasted
MINED --> [*]
MINED --> MINED_IN_STALE_BLOCK: This transaction was mined in a block that became stale after reorg
```

## Microservices
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
github.com/google/uuid v1.6.0
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0
github.com/jackc/pgx/v5 v5.3.1
github.com/jedib0t/go-pretty/v6 v6.5.9
github.com/jmoiron/sqlx v1.3.5
github.com/labstack/echo-contrib v0.17.1
Expand Down Expand Up @@ -99,6 +100,8 @@ require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/invopop/yaml v0.3.1 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.9 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ github.com/jackc/pgtype v1.14.0 h1:y+xUdabmyMkJLyApYuPj38mW+aAIqCe5uuBB51rH3Vw=
github.com/jackc/pgtype v1.14.0/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4=
github.com/jackc/pgx/v4 v4.18.1 h1:YP7G1KABtKpB5IHrO9vYwSrCOhs7p3uqhvhhQBptya0=
github.com/jackc/pgx/v4 v4.18.1/go.mod h1:FydWkUyadDmdNH/mHnGob881GawxeEm7TcMCzkb+qQE=
github.com/jackc/pgx/v5 v5.3.1 h1:Fcr8QJ1ZeLi5zsPZqQeUZhNhxfkkKBOgJuYkJHoBOtU=
github.com/jackc/pgx/v5 v5.3.1/go.mod h1:t3JDKnCBlYIc0ewLF0Q7B8MXmoIaBOZj/ic7iHozM/8=
github.com/jedib0t/go-pretty/v6 v6.5.9 h1:ACteMBRrrmm1gMsXe9PSTOClQ63IXDUt03H5U+UV8OU=
github.com/jedib0t/go-pretty/v6 v6.5.9/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E=
github.com/jmoiron/sqlx v1.3.5 h1:vFFPA71p1o5gAeqtEAwLU4dnX2napprKtHr7PYIcN3g=
Expand Down
6 changes: 4 additions & 2 deletions internal/blocktx/background_workers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import (
"testing"
"time"

"github.com/libsv/go-p2p"

"github.com/bitcoin-sv/arc/internal/blocktx"
"github.com/bitcoin-sv/arc/internal/blocktx/mocks"
"github.com/bitcoin-sv/arc/internal/blocktx/store"
storeMocks "github.com/bitcoin-sv/arc/internal/blocktx/store/mocks"
"github.com/libsv/go-p2p"

"github.com/bitcoin-sv/arc/internal/testdata"
"github.com/stretchr/testify/require"

"github.com/bitcoin-sv/arc/internal/testdata"
)

func TestStartFillGaps(t *testing.T) {
Expand Down
45 changes: 19 additions & 26 deletions internal/blocktx/blocktx_api/blocktx_api.pb.go

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

7 changes: 2 additions & 5 deletions internal/blocktx/blocktx_api/blocktx_api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ service BlockTxAPI {
// Health returns the health of the API.
rpc Health (google.protobuf.Empty) returns (HealthResponse) {}

// ClearTransactions clears transaction data
rpc ClearTransactions(ClearData) returns (RowsAffectedResponse) {}

// ClearBlocks clears block data
rpc ClearBlocks(ClearData) returns (RowsAffectedResponse) {}

// ClearBlockTransactionsMap clears block-transaction-map data
rpc ClearBlockTransactionsMap(ClearData) returns (RowsAffectedResponse) {}
// ClearRegisteredTransactions clears registered transactions
rpc ClearRegisteredTransactions(ClearData) returns (RowsAffectedResponse) {}

// DelUnfinishedBlockProcessing deletes unfinished block processing
rpc DelUnfinishedBlockProcessing(DelUnfinishedBlockProcessingRequest) returns (RowsAffectedResponse) {}
Expand Down
Loading
Loading