Browse Source

INSTANTDEX_DECKSIZE

release/v0.1
jl777 9 years ago
parent
commit
69c31c67e8
  1. 29
      iguana/iguana_instantdex.c
  2. 15
      iguana/swaps/iguana_BTCswap.c

29
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; int32_t i,most,r,n,m=0,initials[100]; struct instantdex_stateinfo *state; struct instantdex_event *event; double sum = 0.;
for (i=n=0; i<numstates; i++) if ( maxiters < 1 )
if ( states[i].initialstate != 0 ) maxiters = 1;
for (i=n=most=0; i<numstates; i++)
if ( states[i].initialstate > 0 )
{
printf("initialstate[%d] %d %s\n",i,states[i].initialstate,states[i].name);
initials[n++] = i; initials[n++] = i;
}
if ( n > 0 && n < sizeof(initials)/sizeof(*initials) ) if ( n > 0 && n < sizeof(initials)/sizeof(*initials) )
{ {
for (i=0; i<maxiters; i++) for (i=0; i<maxiters; i++)
{ {
state = &states[initials[rand() % n]]; r = rand() % n;
state = &states[initials[r]];
m = 0; m = 0;
while ( m++ < 1000 && state->initialstate >= 0 ) while ( m++ < 1000 && state->initialstate >= 0 && state->numevents )
{ {
if ( (i % 1000000) == 0 )
fprintf(stderr,"%s ",state->name);
event = &state->events[rand() % state->numevents]; event = &state->events[rand() % state->numevents];
if ( event->nextstateind < 0 ) if ( event->nextstateind < 0 )
break; break;
state = &states[event->nextstateind]; 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) cJSON *InstantDEX_argjson(char *reference,char *message,char *othercoinaddr,char *otherNXTaddr,int32_t iter,int32_t val,int32_t val2)

15
iguana/swaps/iguana_BTCswap.c

@ -14,10 +14,11 @@
******************************************************************************/ ******************************************************************************/
#include "../exchanges/bitcoin.h" #include "../exchanges/bitcoin.h"
#define INSTANTDEX_DECKSIZE 1000
/* https://bitcointalk.org/index.php?topic=1340621.msg13828271#msg13828271 /* https://bitcointalk.org/index.php?topic=1340621.msg13828271#msg13828271
https://bitcointalk.org/index.php?topic=1364951 https://bitcointalk.org/index.php?topic=1364951
Tier Nolan's approach is followed with the following changes: 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. 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 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 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 ) if ( juint(argjson,"verified") != 0 )
swap->otherverifiedcut = 1; swap->otherverifiedcut = 1;
jaddnum(newjson,"verified",swap->otherverifiedcut); 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); instantdex_getpubs(swap,argjson,newjson);
else printf("ERROR: couldnt generate pubkeys\n"); else printf("ERROR: couldnt generate pubkeys\n");
} }
@ -687,7 +688,7 @@ struct instantdex_stateinfo *BTC_initFSM(int32_t *n)
struct instantdex_stateinfo *s = 0; struct instantdex_stateinfo *s = 0;
*n = 2; *n = 2;
// Four initial states are BOB_sentoffer, ALICE_gotoffer, ALICE_sentoffer, BOB_gotoffer // 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) // "BTCabcde are message events from other party (message events capped at length 8)
// "lowercas" are special events, <TX> types: <fee>, <dep>osit, <alt>payment, <acl> is altcoin claim // "lowercas" are special events, <TX> types: <fee>, <dep>osit, <alt>payment, <acl> is altcoin claim
@ -696,7 +697,7 @@ struct instantdex_stateinfo *BTC_initFSM(int32_t *n)
// states instantdex_statecreate(s,n,<Name of State>,handlerfunc,errorhandler,<Timeout State>,<Error State> // states instantdex_statecreate(s,n,<Name of State>,handlerfunc,errorhandler,<Timeout State>,<Error State>
// a given state has a couple of handlers and custom events, with timeouts and errors invoking a bypass // 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 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"); 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","btcfound","BTCdone","BOB_claimedalt");
instantdex_addevent(s,*n,"BOB_sentpayment","BTCprivM","BTCdone","BOB_claimedalt"); instantdex_addevent(s,*n,"BOB_sentpayment","BTCprivM","BTCdone","BOB_claimedalt");
instantdex_addevent(s,*n,"BOB_sentpayment","poll","poll","BOB_sentpayment"); 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); return(s);
} }

Loading…
Cancel
Save