Skip to content

Commit e34fab5

Browse files
authored
feat: store Stacks block miner address value from new rewards payload introduced in stacks-network/stacks-core#3373 (#1413)
1 parent e1e33fe commit e34fab5

11 files changed

+26
-3
lines changed

docker/docker-compose.dev.stacks-krypton-2.1-transition.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
version: '3.7'
22
services:
33
stacks-blockchain:
4-
image: "zone117x/stacks-api-e2e:stacks2.1-transition-feat-segwit-dcae03a"
4+
image: "zone117x/stacks-api-e2e:stacks2.1-transition-d17c6a4"
55
ports:
66
- "18443:18443" # bitcoin regtest JSON-RPC interface
77
- "18444:18444" # bitcoin regtest p2p
88
- "20443:20443" # stacks-node RPC interface
99
- "20444:20444" # stacks-node p2p
1010
environment:
1111
MINE_INTERVAL: 2s
12+
REWARD_RECIPIENT: STQM73RQC4EX0A07KWG1J5ECZJYBZS4SJ4ERC6WN
1213
STACKS_EVENT_OBSERVER: host.docker.internal:3700
1314
# STACKS_LOG_TRACE: 1
1415
# STACKS_LOG_DEBUG: 1

docker/docker-compose.dev.stacks-krypton.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '3.7'
22
services:
33
stacks-blockchain:
4-
image: "zone117x/stacks-api-e2e:stacks2.1-feat-segwit-dcae03a"
4+
image: "zone117x/stacks-api-e2e:stacks2.1-d17c6a4"
55
ports:
66
- "18443:18443" # bitcoin regtest JSON-RPC interface
77
- "18444:18444" # bitcoin regtest p2p

migrations/1605184662317_miner_rewards.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ exports.up = pgm => {
2929
type: 'string',
3030
notNull: true,
3131
},
32+
miner_address: {
33+
type: 'string',
34+
},
3235
coinbase_amount: {
3336
type: 'numeric',
3437
notNull: true,
@@ -49,5 +52,6 @@ exports.up = pgm => {
4952

5053
pgm.createIndex('miner_rewards', 'index_block_hash', { method: 'hash' });
5154
pgm.createIndex('miner_rewards', 'recipient', { method: 'hash' });
55+
pgm.createIndex('miner_rewards', 'miner_address');
5256
pgm.createIndex('miner_rewards', [{ name: 'mature_block_height', sort: 'DESC' }]);
5357
}

src/datastore/common.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ export interface DbMinerReward {
7272
canonical: boolean;
7373
/** STX principal */
7474
recipient: string;
75+
/** STX principal */
76+
miner_address: string | null;
7577
coinbase_amount: bigint;
7678
tx_fees_anchored: bigint;
7779
tx_fees_streamed_confirmed: bigint;
@@ -1020,6 +1022,7 @@ export interface MinerRewardInsertValues {
10201022
mature_block_height: number;
10211023
canonical: boolean;
10221024
recipient: string;
1025+
miner_address: string | null;
10231026
coinbase_amount: PgNumeric;
10241027
tx_fees_anchored: PgNumeric;
10251028
tx_fees_streamed_confirmed: PgNumeric;

src/datastore/pg-store.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,13 +880,14 @@ export class PgStore {
880880
index_block_hash: string;
881881
mature_block_height: number;
882882
recipient: string;
883+
miner_address: string | null;
883884
coinbase_amount: number;
884885
tx_fees_anchored: number;
885886
tx_fees_streamed_confirmed: number;
886887
tx_fees_streamed_produced: number;
887888
}[]
888889
>`
889-
SELECT id, mature_block_height, recipient, block_hash, index_block_hash, from_index_block_hash,
890+
SELECT id, mature_block_height, recipient, miner_address, block_hash, index_block_hash, from_index_block_hash,
890891
canonical, coinbase_amount, tx_fees_anchored, tx_fees_streamed_confirmed, tx_fees_streamed_produced
891892
FROM miner_rewards
892893
WHERE canonical = true AND mature_block_height = ${blockHeight}
@@ -900,6 +901,8 @@ export class PgStore {
900901
canonical: true,
901902
mature_block_height: r.mature_block_height,
902903
recipient: r.recipient,
904+
// If `miner_address` is null then it means pre-Stacks2.1 data, and the `recipient` can be accurately used
905+
miner_address: r.miner_address ?? r.recipient,
903906
coinbase_amount: BigInt(r.coinbase_amount),
904907
tx_fees_anchored: BigInt(r.tx_fees_anchored),
905908
tx_fees_streamed_confirmed: BigInt(r.tx_fees_streamed_confirmed),

src/datastore/pg-write-store.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,8 @@ export class PgWriteStore extends PgStore {
434434
mature_block_height: minerReward.mature_block_height,
435435
canonical: minerReward.canonical,
436436
recipient: minerReward.recipient,
437+
// If `miner_address` is null then it means pre-Stacks2.1 data, and the `recipient` can be accurately used
438+
miner_address: minerReward.miner_address ?? minerReward.recipient,
437439
coinbase_amount: minerReward.coinbase_amount.toString(),
438440
tx_fees_anchored: minerReward.tx_fees_anchored.toString(),
439441
tx_fees_streamed_confirmed: minerReward.tx_fees_streamed_confirmed.toString(),

src/event-stream/core-node-message.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ export interface CoreNodeBlockMessage {
216216
from_stacks_block_hash: string;
217217
/** STX principal */
218218
recipient: string;
219+
/** STX principal (available starting in Stacks 2.1) */
220+
miner_address: string | null;
219221
/** String quoted micro-STX amount. */
220222
coinbase_amount: string;
221223
/** String quoted micro-STX amount. */

src/event-stream/event-server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ async function handleBlockMessage(
265265
from_index_block_hash: minerReward.from_index_consensus_hash,
266266
mature_block_height: msg.block_height,
267267
recipient: minerReward.recipient,
268+
// If `miner_address` is null then it means pre-Stacks2.1 data, and the `recipient` can be accurately used
269+
miner_address: minerReward.miner_address ?? minerReward.recipient,
268270
coinbase_amount: BigInt(minerReward.coinbase_amount),
269271
tx_fees_anchored: BigInt(minerReward.tx_fees_anchored),
270272
tx_fees_streamed_confirmed: BigInt(minerReward.tx_fees_streamed_confirmed),

src/test-utils/test-builders.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ function testMinerReward(args?: TestMinerRewardArgs): DbMinerReward {
504504
mature_block_height: args?.mature_block_height ?? BLOCK_HEIGHT,
505505
canonical: args?.canonical ?? true,
506506
recipient: args?.recipient ?? MINER_RECIPIENT,
507+
miner_address: args?.recipient ?? MINER_RECIPIENT,
507508
coinbase_amount: args?.coinbase_amount ?? COINBASE_AMOUNT,
508509
tx_fees_anchored: args?.tx_fees_anchored ?? TX_FEES_ANCHORED,
509510
tx_fees_streamed_confirmed: args?.tx_fees_streamed_confirmed ?? TX_FEES_STREAMED_CONFIRMED,

src/tests/datastore-tests.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ describe('postgres datastore', () => {
289289
mature_block_height: 68456,
290290
canonical: canonical,
291291
recipient: recipient,
292+
miner_address: recipient,
292293
coinbase_amount: amount,
293294
tx_fees_anchored: txFeeAnchored,
294295
tx_fees_streamed_confirmed: txFeeConfirmed,
@@ -3546,6 +3547,7 @@ describe('postgres datastore', () => {
35463547
from_index_block_hash: '0x33',
35473548
mature_block_height: 3,
35483549
recipient: 'miner-addr1',
3550+
miner_address: 'miner-addr1',
35493551
coinbase_amount: 1000n,
35503552
tx_fees_anchored: 2n,
35513553
tx_fees_streamed_confirmed: 3n,
@@ -3760,6 +3762,7 @@ describe('postgres datastore', () => {
37603762
mature_block_height: 3,
37613763
from_index_block_hash: '0x11',
37623764
recipient: 'miner-addr1',
3765+
miner_address: 'miner-addr1',
37633766
coinbase_amount: 1000n,
37643767
tx_fees_anchored: 2n,
37653768
tx_fees_streamed_confirmed: 3n,
@@ -3771,6 +3774,7 @@ describe('postgres datastore', () => {
37713774
mature_block_height: 4,
37723775
from_index_block_hash: '0x22',
37733776
recipient: 'miner-addr2',
3777+
miner_address: 'miner-addr2',
37743778
coinbase_amount: 1000n,
37753779
tx_fees_anchored: 2n,
37763780
tx_fees_streamed_confirmed: 3n,

0 commit comments

Comments
 (0)