Skip to content

Commit 8dc34ef

Browse files
committed
Revert "fix: bugged re-org logic introduced in microblock implementation #670"
This reverts commit ea4d801.
1 parent 676e662 commit 8dc34ef

File tree

1 file changed

+6
-26
lines changed

1 file changed

+6
-26
lines changed

src/datastore/postgres-store.ts

+6-26
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,6 @@ export class PgDataStore
850850
const { orphanedMicroblocks } = await this.findUnanchoredMicroblocksAtChainTip(
851851
client,
852852
currentMicroblockTip.parent_index_block_hash,
853-
'',
854853
currentMicroblockTip
855854
);
856855
if (orphanedMicroblocks.length > 0) {
@@ -859,7 +858,6 @@ export class PgDataStore
859858
const { orphanedMicroblockTxs } = await this.handleMicroOrphan(
860859
client,
861860
currentMicroblockTip.parent_index_block_hash,
862-
'',
863861
true,
864862
orphanedMicroblocks
865863
);
@@ -917,14 +915,11 @@ export class PgDataStore
917915
`
918916
SELECT microblock_hash
919917
FROM microblocks
920-
WHERE parent_index_block_hash = $1
921-
AND microblock_hash = ANY($2)
922-
AND (index_block_hash = $3 OR index_block_hash = '\\x'::bytea)
918+
WHERE parent_index_block_hash = $1 AND microblock_hash = ANY($2)
923919
`,
924920
[
925921
hexToBuffer(data.block.parent_index_block_hash),
926922
data.microblocks.map(mb => hexToBuffer(mb.microblock_hash)),
927-
hexToBuffer(data.block.index_block_hash),
928923
]
929924
);
930925
const existingMicroblockHashes = new Set(
@@ -981,15 +976,13 @@ export class PgDataStore
981976
} = await this.findUnanchoredMicroblocksAtChainTip(
982977
client,
983978
data.block.parent_index_block_hash,
984-
data.block.index_block_hash,
985979
acceptedMicroblockTip
986980
);
987981

988982
if (orphanedMicroblocks.length > 0) {
989983
const { orphanedMicroblockTxs } = await this.handleMicroOrphan(
990984
client,
991985
data.block.parent_index_block_hash,
992-
data.block.index_block_hash,
993986
isCanonical,
994987
orphanedMicroblocks
995988
);
@@ -1011,15 +1004,13 @@ export class PgDataStore
10111004
SET microblock_canonical = true, canonical = $1, index_block_hash = $2, block_hash = $3
10121005
WHERE parent_index_block_hash = $4
10131006
AND microblock_hash = ANY($5)
1014-
AND (index_block_hash = $6 OR index_block_hash = '\\x'::bytea)
10151007
`,
10161008
[
10171009
isCanonical,
10181010
hexToBuffer(data.block.index_block_hash),
10191011
hexToBuffer(data.block.block_hash),
10201012
hexToBuffer(data.block.parent_index_block_hash),
10211013
acceptedMicroblocks.map(mb => hexToBuffer(mb)),
1022-
hexToBuffer(data.block.index_block_hash),
10231014
]
10241015
);
10251016
// Note: this assumes the stacks-node will never send the same combination of (microblock_hash, parent_index_block_hash) more than once.
@@ -1036,7 +1027,6 @@ export class PgDataStore
10361027
UPDATE txs
10371028
SET microblock_canonical = true, canonical = $1, index_block_hash = $2, block_hash = $3, burn_block_time = $4
10381029
WHERE parent_index_block_hash = $5
1039-
AND (index_block_hash = $2 OR index_block_hash = '\\x'::bytea)
10401030
AND microblock_hash = ANY($6)
10411031
RETURNING tx_id, microblock_hash
10421032
`,
@@ -1199,7 +1189,6 @@ export class PgDataStore
11991189
async handleMicroOrphan(
12001190
client: ClientBase,
12011191
parentIndexBlockHash: string,
1202-
indexBlockHash: string,
12031192
isCanonical: boolean,
12041193
orphanedMicroblocks: string[]
12051194
): Promise<{ orphanedMicroblockTxs: string[] }> {
@@ -1210,13 +1199,8 @@ export class PgDataStore
12101199
SET microblock_canonical = false
12111200
WHERE parent_index_block_hash = $1
12121201
AND microblock_hash = ANY($2)
1213-
AND (index_block_hash = $3 OR index_block_hash = '\\x'::bytea)
12141202
`,
1215-
[
1216-
hexToBuffer(parentIndexBlockHash),
1217-
orphanedMicroblocks.map(mb => hexToBuffer(mb)),
1218-
hexToBuffer(indexBlockHash),
1219-
]
1203+
[hexToBuffer(parentIndexBlockHash), orphanedMicroblocks.map(mb => hexToBuffer(mb))]
12201204
);
12211205
if (orphanMicroblocksQuery.rowCount !== orphanedMicroblocks.length) {
12221206
throw new Error(`Unexpected number of rows updated when setting microblock_canonical`);
@@ -1231,14 +1215,12 @@ export class PgDataStore
12311215
SET microblock_canonical = false, canonical = $1
12321216
WHERE parent_index_block_hash = $2
12331217
AND microblock_hash = ANY($3)
1234-
AND index_block_hash = $4
1235-
RETURNING tx_id, microblock_hash, block_hash
1218+
RETURNING tx_id, microblock_hash
12361219
`,
12371220
[
12381221
isCanonical,
12391222
hexToBuffer(parentIndexBlockHash),
12401223
orphanedMicroblocks.map(mb => hexToBuffer(mb)),
1241-
hexToBuffer(indexBlockHash),
12421224
]
12431225
);
12441226
orphanedMbTxsQuery.rows.forEach(row => {
@@ -1280,7 +1262,6 @@ export class PgDataStore
12801262
async findUnanchoredMicroblocksAtChainTip(
12811263
client: ClientBase,
12821264
parentIndexBlockHash: string,
1283-
indexBlockHash: string,
12841265
microblockChainTip: DbMicroblock | undefined
12851266
): Promise<{ acceptedMicroblocks: string[]; orphanedMicroblocks: string[] }> {
12861267
// Get any microblocks that this anchor block is responsible for accepting or rejecting.
@@ -1291,9 +1272,8 @@ export class PgDataStore
12911272
SELECT ${MICROBLOCK_COLUMNS}
12921273
FROM microblocks
12931274
WHERE parent_index_block_hash = $1
1294-
AND (index_block_hash = $2 OR index_block_hash = '\\x'::bytea)
12951275
`,
1296-
[hexToBuffer(parentIndexBlockHash), hexToBuffer(indexBlockHash)]
1276+
[hexToBuffer(parentIndexBlockHash)]
12971277
);
12981278
const candidateMicroblocks = mbQuery.rows.map(row => this.parseMicroblockQueryResult(row));
12991279

@@ -2775,8 +2755,8 @@ export class PgDataStore
27752755
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19,
27762756
$20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35, $36, $37
27772757
)
2778-
ON CONFLICT ON CONSTRAINT unique_tx_id_index_block_hash
2779-
DO NOTHING
2758+
-- ON CONFLICT ON CONSTRAINT unique_tx_id_index_block_hash
2759+
-- DO NOTHING
27802760
`,
27812761
[
27822762
hexToBuffer(tx.tx_id),

0 commit comments

Comments
 (0)