Add back events overflow protection

This commit is contained in:
jl777
2018-04-15 23:38:48 +03:00
parent 3b6dda83b1
commit dbed0ea52f

View File

@@ -1,5 +1,5 @@
/****************************************************************************** /******************************************************************************
* Copyright © 2014-2017 The SuperNET Developers. * * Copyright © 2014-2018 The SuperNET Developers. *
* * * *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright * * the top-level directory of this distribution for the individual copyright *
@@ -20,7 +20,7 @@
struct komodo_event *komodo_eventadd(struct komodo_state *sp,int32_t height,char *symbol,uint8_t type,uint8_t *data,uint16_t datalen) struct komodo_event *komodo_eventadd(struct komodo_state *sp,int32_t height,char *symbol,uint8_t type,uint8_t *data,uint16_t datalen)
{ {
struct komodo_event *ep=0; uint16_t len = (uint16_t)(sizeof(*ep) + datalen); struct komodo_event *ep=0; uint16_t len = (uint16_t)(sizeof(*ep) + datalen);
if ( sp != 0 ) if ( sp != 0 && ASSETCHAINS_SYMBOL[0] != 0 )
{ {
portable_mutex_lock(&komodo_mutex); portable_mutex_lock(&komodo_mutex);
ep = (struct komodo_event *)calloc(1,len); ep = (struct komodo_event *)calloc(1,len);
@@ -37,10 +37,10 @@ struct komodo_event *komodo_eventadd(struct komodo_state *sp,int32_t height,char
return(ep); return(ep);
} }
void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t height,char *dest,uint256 notarized_hash,uint256 notarized_desttxid,int32_t notarizedheight) void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t height,char *dest,uint256 notarized_hash,uint256 notarized_desttxid,int32_t notarizedheight)//,uint256 MoM,int32_t MoMdepth)
{ {
struct komodo_event_notarized N; struct komodo_event_notarized N;
if ( komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid) != 0 ) if ( NOTARY_PUBKEY33[0] != 0 && komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid) != 0 )
{ {
if ( height > 50000 || ASSETCHAINS_SYMBOL[0] != 0 ) if ( height > 50000 || ASSETCHAINS_SYMBOL[0] != 0 )
printf("[%s] error validating notarization ht.%d notarized_height.%d, if on a pruned %s node this can be ignored\n",ASSETCHAINS_SYMBOL,height,notarizedheight,dest); printf("[%s] error validating notarization ht.%d notarized_height.%d, if on a pruned %s node this can be ignored\n",ASSETCHAINS_SYMBOL,height,notarizedheight,dest);
@@ -53,10 +53,12 @@ void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t heig
N.blockhash = notarized_hash; N.blockhash = notarized_hash;
N.desttxid = notarized_desttxid; N.desttxid = notarized_desttxid;
N.notarizedheight = notarizedheight; N.notarizedheight = notarizedheight;
strcpy(N.dest,dest); //N.MoM = MoM;
//N.MoMdepth = MoMdepth;
strncpy(N.dest,dest,sizeof(N.dest)-1);
komodo_eventadd(sp,height,symbol,KOMODO_EVENT_NOTARIZED,(uint8_t *)&N,sizeof(N)); komodo_eventadd(sp,height,symbol,KOMODO_EVENT_NOTARIZED,(uint8_t *)&N,sizeof(N));
if ( sp != 0 ) if ( sp != 0 )
komodo_notarized_update(sp,height,notarizedheight,notarized_hash,notarized_desttxid); komodo_notarized_update(sp,height,notarizedheight,notarized_hash,notarized_desttxid)//,MoM,MoMdepth);
} }
} }
@@ -75,18 +77,23 @@ void komodo_eventadd_pubkeys(struct komodo_state *sp,char *symbol,int32_t height
void komodo_eventadd_pricefeed(struct komodo_state *sp,char *symbol,int32_t height,uint32_t *prices,uint8_t num) void komodo_eventadd_pricefeed(struct komodo_state *sp,char *symbol,int32_t height,uint32_t *prices,uint8_t num)
{ {
struct komodo_event_pricefeed F; struct komodo_event_pricefeed F;
if ( num == sizeof(F.prices)/sizeof(*F.prices) )
{
memset(&F,0,sizeof(F)); memset(&F,0,sizeof(F));
F.num = num; F.num = num;
memcpy(F.prices,prices,sizeof(*F.prices) * num); memcpy(F.prices,prices,sizeof(*F.prices) * num);
komodo_eventadd(sp,height,symbol,KOMODO_EVENT_PRICEFEED,(uint8_t *)&F,(int32_t)(sizeof(F.num) + sizeof(*F.prices) * num)); komodo_eventadd(sp,height,symbol,KOMODO_EVENT_PRICEFEED,(uint8_t *)&F,(int32_t)(sizeof(F.num) + sizeof(*F.prices) * num));
if ( sp != 0 ) if ( sp != 0 )
komodo_pvals(height,prices,num); komodo_pvals(height,prices,num);
} else fprintf(stderr,"skip pricefeed[%d]\n",num);
} }
void komodo_eventadd_opreturn(struct komodo_state *sp,char *symbol,int32_t height,uint256 txid,uint64_t value,uint16_t vout,uint8_t *buf,uint16_t opretlen) void komodo_eventadd_opreturn(struct komodo_state *sp,char *symbol,int32_t height,uint256 txid,uint64_t value,uint16_t vout,uint8_t *buf,uint16_t opretlen)
{ {
struct komodo_event_opreturn O; uint8_t opret[16384]; struct komodo_event_opreturn O; uint8_t *opret;
memset(&O,0,sizeof(O)); if ( ASSETCHAINS_SYMBOL[0] != 0 )
{
opret = (uint8_t *)calloc(1,sizeof(O) + opretlen + 16);
O.txid = txid; O.txid = txid;
O.value = value; O.value = value;
O.vout = vout; O.vout = vout;
@@ -94,9 +101,11 @@ void komodo_eventadd_opreturn(struct komodo_state *sp,char *symbol,int32_t heigh
memcpy(&opret[sizeof(O)],buf,opretlen); memcpy(&opret[sizeof(O)],buf,opretlen);
O.oplen = (int32_t)(opretlen + sizeof(O)); O.oplen = (int32_t)(opretlen + sizeof(O));
komodo_eventadd(sp,height,symbol,KOMODO_EVENT_OPRETURN,opret,O.oplen); komodo_eventadd(sp,height,symbol,KOMODO_EVENT_OPRETURN,opret,O.oplen);
free(opret);
if ( sp != 0 ) if ( sp != 0 )
komodo_opreturn(height,value,buf,opretlen,txid,vout,symbol); komodo_opreturn(height,value,buf,opretlen,txid,vout,symbol);
} }
}
void komodo_event_undo(struct komodo_state *sp,struct komodo_event *ep) void komodo_event_undo(struct komodo_state *sp,struct komodo_event *ep)
{ {
@@ -169,6 +178,7 @@ void komodo_eventadd_kmdheight(struct komodo_state *sp,char *symbol,int32_t heig
} }
else else
{ {
//fprintf(stderr,"REWIND kmdheight.%d\n",kmdheight);
kmdheight = -kmdheight; kmdheight = -kmdheight;
komodo_eventadd(sp,height,symbol,KOMODO_EVENT_REWIND,(uint8_t *)&height,sizeof(height)); komodo_eventadd(sp,height,symbol,KOMODO_EVENT_REWIND,(uint8_t *)&height,sizeof(height));
if ( sp != 0 ) if ( sp != 0 )