diff --git a/iguana/iguana_instantdex.c b/iguana/iguana_instantdex.c index 97f78ec31..2982cb70a 100755 --- a/iguana/iguana_instantdex.c +++ b/iguana/iguana_instantdex.c @@ -184,29 +184,42 @@ struct instantdex_event *instantdex_addevent(struct instantdex_stateinfo *states } } -int32_t instantdex_FSMtest(struct instantdex_stateinfo *states,int32_t numstates) +double instantdex_FSMtest(struct instantdex_stateinfo *states,int32_t numstates,int32_t maxiters) { - int32_t i,n,m=0,initials[100],maxiters = 1; struct instantdex_stateinfo *state; struct instantdex_event *event; - for (i=n=0; i 0 ) + { + printf("initialstate[%d] %d %s\n",i,states[i].initialstate,states[i].name); initials[n++] = i; + } if ( n > 0 && n < sizeof(initials)/sizeof(*initials) ) { for (i=0; iinitialstate >= 0 ) + while ( m++ < 1000 && state->initialstate >= 0 && state->numevents ) { + if ( (i % 1000000) == 0 ) + fprintf(stderr,"%s ",state->name); event = &state->events[rand() % state->numevents]; if ( event->nextstateind < 0 ) break; state = &states[event->nextstateind]; } - printf("reached terminal state.%s after m.%d events\n",state->name,m); + if ( m > most ) + most = m; + sum += m; + if ( (i % 1000000) == 0 ) + fprintf(stderr,"reached %s m.%d events most.%d ave %.2f\n",state->name,m,most,sum/(i+1)); } } - return(m); + fprintf(stderr," most.%d ave %.2f\n",most,sum/(i+1)); + return(sum / maxiters); } cJSON *InstantDEX_argjson(char *reference,char *message,char *othercoinaddr,char *otherNXTaddr,int32_t iter,int32_t val,int32_t val2) diff --git a/iguana/swaps/iguana_BTCswap.c b/iguana/swaps/iguana_BTCswap.c index ed35f80be..5d853aa3e 100755 --- a/iguana/swaps/iguana_BTCswap.c +++ b/iguana/swaps/iguana_BTCswap.c @@ -14,10 +14,11 @@ ******************************************************************************/ #include "../exchanges/bitcoin.h" +#define INSTANTDEX_DECKSIZE 1000 /* https://bitcointalk.org/index.php?topic=1340621.msg13828271#msg13828271 https://bitcointalk.org/index.php?topic=1364951 Tier Nolan's approach is followed with the following changes: - a) instead of cutting 1000 keypairs, only 777 are a + a) instead of cutting 1000 keypairs, only INSTANTDEX_DECKSIZE are a b) instead of sending the entire 256 bits, it is truncated to 64 bits. With odds of collision being so low, it is dwarfed by the ~0.1% insurance factor. c) D is set to 100x the insurance rate of 1/777 12.87% + BTC amount d) insurance is added to Bob's payment, which is after the deposit and bailin @@ -496,7 +497,7 @@ cJSON *instantdex_parseargjson(struct supernet_info *myinfo,struct exchange_info if ( juint(argjson,"verified") != 0 ) swap->otherverifiedcut = 1; jaddnum(newjson,"verified",swap->otherverifiedcut); - if ( instantdex_pubkeyargs(swap,newjson,2 + deckflag*777,myinfo->persistent_priv,swap->orderhash,0x02+swap->isbob) == 2 + deckflag*777 ) + if ( instantdex_pubkeyargs(swap,newjson,2 + deckflag*INSTANTDEX_DECKSIZE,myinfo->persistent_priv,swap->orderhash,0x02+swap->isbob) == 2 + deckflag*INSTANTDEX_DECKSIZE ) instantdex_getpubs(swap,argjson,newjson); else printf("ERROR: couldnt generate pubkeys\n"); } @@ -687,7 +688,7 @@ struct instantdex_stateinfo *BTC_initFSM(int32_t *n) struct instantdex_stateinfo *s = 0; *n = 2; // Four initial states are BOB_sentoffer, ALICE_gotoffer, ALICE_sentoffer, BOB_gotoffer - // the initiator includes signed feetx and deck of 777 keypairs + // the initiator includes signed feetx and deck of INSTANTDEX_DECKSIZE keypairs // // "BTCabcde are message events from other party (message events capped at length 8) // "lowercas" are special events, types: , osit, payment, is altcoin claim @@ -696,7 +697,7 @@ struct instantdex_stateinfo *BTC_initFSM(int32_t *n) // states instantdex_statecreate(s,n,,handlerfunc,errorhandler,, // a given state has a couple of handlers and custom events, with timeouts and errors invoking a bypass - s = instantdex_statecreate(s,n,"BTC_cleanup",BTC_cleanupfunc,0,0,0,0); // from states without any commits + s = instantdex_statecreate(s,n,"BTC_cleanup",BTC_cleanupfunc,0,0,0,-1); // from states without any commits s = instantdex_statecreate(s,n,"BOB_reclaim",BOB_reclaimfunc,0,0,0,0); // Bob's gets his deposit back instantdex_addevent(s,*n,"BOB_reclaim","brcfound","poll","BTC_cleanup"); @@ -791,7 +792,11 @@ struct instantdex_stateinfo *BTC_initFSM(int32_t *n) instantdex_addevent(s,*n,"BOB_sentpayment","btcfound","BTCdone","BOB_claimedalt"); instantdex_addevent(s,*n,"BOB_sentpayment","BTCprivM","BTCdone","BOB_claimedalt"); instantdex_addevent(s,*n,"BOB_sentpayment","poll","poll","BOB_sentpayment"); - instantdex_FSMtest(s,*n); + { + double startmillis = OS_milliseconds(); + instantdex_FSMtest(s,*n,10000000); + printf("elapsed %.3f ave %.6f\n",OS_milliseconds() - startmillis,(OS_milliseconds() - startmillis)/10000000); + } return(s); }