@@ -606,6 +606,7 @@ interface EventMessageHandler {
606
606
function createMessageProcessorQueue ( ) : EventMessageHandler {
607
607
// Create a promise queue so that only one message is handled at a time.
608
608
const processorQueue = new PQueue ( { concurrency : 1 } ) ;
609
+
609
610
const handler : EventMessageHandler = {
610
611
handleRawEventRequest : ( eventPath : string , payload : any , db : PgWriteStore ) => {
611
612
return processorQueue
@@ -728,105 +729,114 @@ export async function startEventServer(opts: {
728
729
. json ( { status : 'ready' , msg : 'API event server listening for core-node POST messages' } ) ;
729
730
} ) ;
730
731
731
- app . post (
732
- '*' ,
733
- asyncHandler ( async ( req , res , next ) => {
732
+ const handleRawEventRequest = asyncHandler ( async req => {
733
+ await messageHandler . handleRawEventRequest ( req . path , req . body , db ) ;
734
+
735
+ if ( logger . isDebugEnabled ( ) ) {
734
736
const eventPath = req . path ;
735
737
let payload = JSON . stringify ( req . body ) ;
736
- await messageHandler . handleRawEventRequest ( eventPath , req . body , db ) ;
737
- if ( logger . isDebugEnabled ( ) ) {
738
- // Skip logging massive event payloads, this _should_ only exclude the genesis block payload which is ~80 MB.
739
- if ( payload . length > 10_000_000 ) {
740
- payload = 'payload body too large for logging' ;
741
- }
742
- logger . debug ( `[stacks-node event] ${ eventPath } ${ payload } ` ) ;
738
+ // Skip logging massive event payloads, this _should_ only exclude the genesis block payload which is ~80 MB.
739
+ if ( payload . length > 10_000_000 ) {
740
+ payload = 'payload body too large for logging' ;
743
741
}
744
- next ( ) ;
745
- } )
746
- ) ;
742
+ logger . debug ( `[stacks-node event] ${ eventPath } ${ payload } ` ) ;
743
+ }
744
+ } ) ;
747
745
748
746
app . post (
749
747
'/new_block' ,
750
- asyncHandler ( async ( req , res ) => {
748
+ asyncHandler ( async ( req , res , next ) => {
751
749
try {
752
750
const msg : CoreNodeBlockMessage = req . body ;
753
751
await messageHandler . handleBlockMessage ( opts . chainId , msg , db ) ;
754
752
res . status ( 200 ) . json ( { result : 'ok' } ) ;
753
+ next ( ) ;
755
754
} catch ( error ) {
756
755
logError ( `error processing core-node /new_block: ${ error } ` , error ) ;
757
756
res . status ( 500 ) . json ( { error : error } ) ;
758
757
}
759
- } )
758
+ } ) ,
759
+ handleRawEventRequest
760
760
) ;
761
761
762
762
app . post (
763
763
'/new_burn_block' ,
764
- asyncHandler ( async ( req , res ) => {
764
+ asyncHandler ( async ( req , res , next ) => {
765
765
try {
766
766
const msg : CoreNodeBurnBlockMessage = req . body ;
767
767
await messageHandler . handleBurnBlock ( msg , db ) ;
768
768
res . status ( 200 ) . json ( { result : 'ok' } ) ;
769
+ next ( ) ;
769
770
} catch ( error ) {
770
771
logError ( `error processing core-node /new_burn_block: ${ error } ` , error ) ;
771
772
res . status ( 500 ) . json ( { error : error } ) ;
772
773
}
773
- } )
774
+ } ) ,
775
+ handleRawEventRequest
774
776
) ;
775
777
776
778
app . post (
777
779
'/new_mempool_tx' ,
778
- asyncHandler ( async ( req , res ) => {
780
+ asyncHandler ( async ( req , res , next ) => {
779
781
try {
780
782
const rawTxs : string [ ] = req . body ;
781
783
await messageHandler . handleMempoolTxs ( rawTxs , db ) ;
782
784
res . status ( 200 ) . json ( { result : 'ok' } ) ;
785
+ next ( ) ;
783
786
} catch ( error ) {
784
787
logError ( `error processing core-node /new_mempool_tx: ${ error } ` , error ) ;
785
788
res . status ( 500 ) . json ( { error : error } ) ;
786
789
}
787
- } )
790
+ } ) ,
791
+ handleRawEventRequest
788
792
) ;
789
793
790
794
app . post (
791
795
'/drop_mempool_tx' ,
792
- asyncHandler ( async ( req , res ) => {
796
+ asyncHandler ( async ( req , res , next ) => {
793
797
try {
794
798
const msg : CoreNodeDropMempoolTxMessage = req . body ;
795
799
await messageHandler . handleDroppedMempoolTxs ( msg , db ) ;
796
800
res . status ( 200 ) . json ( { result : 'ok' } ) ;
801
+ next ( ) ;
797
802
} catch ( error ) {
798
803
logError ( `error processing core-node /drop_mempool_tx: ${ error } ` , error ) ;
799
804
res . status ( 500 ) . json ( { error : error } ) ;
800
805
}
801
- } )
806
+ } ) ,
807
+ handleRawEventRequest
802
808
) ;
803
809
804
810
app . post (
805
811
'/attachments/new' ,
806
- asyncHandler ( async ( req , res ) => {
812
+ asyncHandler ( async ( req , res , next ) => {
807
813
try {
808
814
const msg : CoreNodeAttachmentMessage [ ] = req . body ;
809
815
await messageHandler . handleNewAttachment ( msg , db ) ;
810
816
res . status ( 200 ) . json ( { result : 'ok' } ) ;
817
+ next ( ) ;
811
818
} catch ( error ) {
812
819
logError ( `error processing core-node /attachments/new: ${ error } ` , error ) ;
813
820
res . status ( 500 ) . json ( { error : error } ) ;
814
821
}
815
- } )
822
+ } ) ,
823
+ handleRawEventRequest
816
824
) ;
817
825
818
826
app . post (
819
827
'/new_microblocks' ,
820
- asyncHandler ( async ( req , res ) => {
828
+ asyncHandler ( async ( req , res , next ) => {
821
829
try {
822
830
const msg : CoreNodeMicroblockMessage = req . body ;
823
831
await messageHandler . handleMicroblockMessage ( opts . chainId , msg , db ) ;
824
832
res . status ( 200 ) . json ( { result : 'ok' } ) ;
833
+ next ( ) ;
825
834
} catch ( error ) {
826
835
logError ( `error processing core-node /new_microblocks: ${ error } ` , error ) ;
827
836
res . status ( 500 ) . json ( { error : error } ) ;
828
837
}
829
- } )
838
+ } ) ,
839
+ handleRawEventRequest
830
840
) ;
831
841
832
842
app . post ( '*' , ( req , res , next ) => {
0 commit comments