@@ -78,6 +78,7 @@ import {
7878 validateZonefileHash ,
7979 newReOrgUpdatedEntities ,
8080 PgWriteQueue ,
81+ removeNullBytes ,
8182} from './helpers' ;
8283import { PgNotifier } from './pg-notifier' ;
8384import { MIGRATIONS_DIR , PgStore } from './pg-store' ;
@@ -203,6 +204,13 @@ export class PgWriteStore extends PgStore {
203204 }
204205
205206 async storeRawEventRequest ( eventPath : string , payload : any ) : Promise < void > {
207+ if ( eventPath === '/new_block' && typeof payload === 'object' ) {
208+ for ( const tx of payload . transactions ) {
209+ if ( 'vm_error' in tx && tx . vm_error ) {
210+ tx . vm_error = removeNullBytes ( tx . vm_error ) ;
211+ }
212+ }
213+ }
206214 await this . sqlWriteTransaction ( async sql => {
207215 const insertResult = await sql <
208216 {
@@ -1930,35 +1938,8 @@ export class PgWriteStore extends PgStore {
19301938 } ;
19311939 }
19321940
1933- async updateBurnchainRewards ( {
1934- burnchainBlockHash,
1935- burnchainBlockHeight,
1936- rewards,
1937- } : {
1938- burnchainBlockHash : string ;
1939- burnchainBlockHeight : number ;
1940- rewards : DbBurnchainReward [ ] ;
1941- } ) : Promise < void > {
1941+ async updateBurnchainRewards ( { rewards } : { rewards : DbBurnchainReward [ ] } ) : Promise < void > {
19421942 return await this . sqlWriteTransaction ( async sql => {
1943- const existingRewards = await sql <
1944- {
1945- reward_recipient : string ;
1946- reward_amount : string ;
1947- } [ ]
1948- > `
1949- UPDATE burnchain_rewards
1950- SET canonical = false
1951- WHERE canonical = true AND
1952- (burn_block_hash = ${ burnchainBlockHash }
1953- OR burn_block_height >= ${ burnchainBlockHeight } )
1954- ` ;
1955-
1956- if ( existingRewards . count > 0 ) {
1957- logger . warn (
1958- `Invalidated ${ existingRewards . count } burnchain rewards after fork detected at burnchain block ${ burnchainBlockHash } `
1959- ) ;
1960- }
1961-
19621943 for ( const reward of rewards ) {
19631944 const values : BurnchainRewardInsertValues = {
19641945 canonical : true ,
@@ -2062,7 +2043,9 @@ export class PgWriteStore extends PgStore {
20622043 token_transfer_memo : tx . token_transfer_memo ?? null ,
20632044 smart_contract_clarity_version : tx . smart_contract_clarity_version ?? null ,
20642045 smart_contract_contract_id : tx . smart_contract_contract_id ?? null ,
2065- smart_contract_source_code : tx . smart_contract_source_code ?? null ,
2046+ smart_contract_source_code : tx . smart_contract_source_code
2047+ ? removeNullBytes ( tx . smart_contract_source_code )
2048+ : null ,
20662049 contract_call_contract_id : tx . contract_call_contract_id ?? null ,
20672050 contract_call_function_name : tx . contract_call_function_name ?? null ,
20682051 contract_call_function_args : tx . contract_call_function_args ?? null ,
@@ -2085,7 +2068,7 @@ export class PgWriteStore extends PgStore {
20852068 execution_cost_runtime : tx . execution_cost_runtime ,
20862069 execution_cost_write_count : tx . execution_cost_write_count ,
20872070 execution_cost_write_length : tx . execution_cost_write_length ,
2088- vm_error : tx . vm_error ?? null ,
2071+ vm_error : tx . vm_error ? removeNullBytes ( tx . vm_error ) : null ,
20892072 } ) ) ;
20902073
20912074 let count = 0 ;
@@ -3615,6 +3598,11 @@ export class PgWriteStore extends PgStore {
36153598 if ( orphanedBlockResult . length > 0 ) {
36163599 const orphanedBlocks = orphanedBlockResult . map ( b => parseBlockQueryResult ( b ) ) ;
36173600 for ( const orphanedBlock of orphanedBlocks ) {
3601+ await sql `
3602+ UPDATE burnchain_rewards
3603+ SET canonical = false
3604+ WHERE canonical = true AND burn_block_hash = ${ orphanedBlock . burn_block_hash }
3605+ ` ;
36183606 const microCanonicalUpdateResult = await this . updateMicroCanonical ( sql , {
36193607 isCanonical : false ,
36203608 blockHeight : orphanedBlock . block_height ,
0 commit comments