Skip to content

Commit

Permalink
Additional v2.4.1 Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
stackoverflo committed Dec 24, 2019
1 parent 90143d5 commit ad45c88
Show file tree
Hide file tree
Showing 23 changed files with 311 additions and 123 deletions.
16 changes: 16 additions & 0 deletions CHANGES.TXT
Expand Up @@ -5,6 +5,22 @@
*/

Patch Level 37 (Mochimo v2.4.1)

Changed PATCHLEVEL to 37 in mochimo.c and minertest.c
Changed VERSIONSTR to "37" in mochimo.c and minertest.c
Fixed previous hash check in checkproof() in proof.c
Added byte Insyncup; /* non-zero when syncup() runs */ to data.c
Added Insyncup to syncup() in syncup.c
Added addrlen to le_find() in ledger.c
Added Tagidx[] to tag.c
Changed tag_find() in tag.c, txclean.c, and mtxval.c
Added tag_free() to tag.c, update.c
Changed pval.c server.c, and config.h to allow 0xff pseudo-blocks
Removed bigwait from server.c
Added proper time_t vtime for vstart.lck check in server.c
Added Insyncup to update() in update.c to help plog()'s
Added char *solvestr to update() to reckon pushed, solved, and updated blocks.
Simplified parameter logic in tag_valid() and calls from bval and txval.c.
Added Syncup Function, Removing Contention
made mochimo/bin/d/split
modified bx.c to indicate tags not found in MTX.
Expand Down
2 changes: 1 addition & 1 deletion src/bval.c
Expand Up @@ -310,7 +310,7 @@ int main(int argc, char **argv)
if(cmp64(src_le.balance, total) != 0)
drop("bad transaction total");
if(!ismtx(&tx)) {
if(tag_valid(tx.src_addr, tx.chg_addr, tx.dst_addr, 0, bt.bnum)
if(tag_valid(tx.src_addr, tx.chg_addr, tx.dst_addr, bt.bnum)
!= VEOK) drop("tag not valid");
} else {
if(mtx_val((MTX *) &tx, Mfee) != 0) drop("bad mtx_val()");
Expand Down
18 changes: 15 additions & 3 deletions src/bx.c
Expand Up @@ -432,15 +432,27 @@ void disp_bh(BHEADER *bh, BTRAILER *bt)
/* Hex converter */
void hexcon(void)
{
char buff[81];
char buff[81], *cp;
unsigned long val;
int n;

for(;;) {
printf("Enter value (e.g. decimal 123, or hex 0123, p=previous): ");
printf("Enter value (e.g. 'string, or decimal 123, or hex 0123,"
" p=previous):\n");
tgets(buff, 80);
if(*buff == '\'') {
printf("0x");
for(cp = buff + 1; *cp; cp++) printf("%02x", *cp);
printf("\n");
continue;
}
if(buff[0] < '0' || buff[0] > '9') break;
val = getval(buff);
printf("%lu (0x%lx) [0x%s]\n", val, val, b2hex8((byte *) &val));
printf("%lu (0x%lx) [0x%s] ", val, val, b2hex8((byte *) &val));
for(cp = (char *) &val, n = sizeof(val); n; n--, cp++) {
if(*cp >= ' ' && *cp < 127) printf("%c", *cp); else printf(".");
}
printf("\n");
} /* end for */
}

Expand Down
6 changes: 3 additions & 3 deletions src/config.h
Expand Up @@ -87,13 +87,13 @@
/* NEWYEAR trigger */
#define NEWYEAR(bnum) (get32(bnum) >= V23TRIGGER || get32(bnum+4) != 0)

#define WATCHTIME (BRIDGE*4+1) /* Default minimum watchdog time for -w switch */
#define WATCHTIME (BRIDGE*4+1) /* minimum watchdog time */
#define BRIDGE 949 /* Trouble time -- Edit for testing */
#define TIMES_OF_TROUBLE() (Ltime >= Bridgetime \
&& Cblocknum[0] != 0xfe \
&& (get32(Cblocknum) >= V23TRIGGER \
|| get32(Cblocknum+4) != 0))
#ifndef UBANDWIDTH

#ifndef UBANDWIDTH
#define UBANDWIDTH 14300 /* Dynamic upload bandwidth -- not zero */
#endif

Expand Down
1 change: 1 addition & 0 deletions src/data.c
Expand Up @@ -72,6 +72,7 @@ word32 Coreplist[CORELISTLEN] = { /* ip's of the Core Network */

int Quorum = 4; /* Number of peers in get_eon() gang[MAXQUORUM] */
byte Ininit; /* non-zero when init() runs */
byte Insyncup; /* non-zero when syncup() runs */
byte Safemode; /* Safe mode enable */
byte Nominer; /* Do not start miner if true -n */
word32 Watchdog; /* enable watchdog timeout -wN */
Expand Down
10 changes: 4 additions & 6 deletions src/ledger.c
@@ -1,4 +1,4 @@
/* ledger.c Search, read, and write to ledger.dat
/* ledger.c Open, close, and search ledger.dat
*
* Copyright (c) 2019 by Adequate Systems, LLC. All Rights Reserved.
* See LICENSE.PDF **** NO WARRANTY ****
Expand Down Expand Up @@ -55,6 +55,7 @@ void le_close(void)
int le_find(byte *addr, LENTRY *le, long *position, int mode)
{
long cond, mid, hi, low;
size_t addrlen;

if(Lefp == NULL) {
Lerror = error("le_find(): use le_open() first!");
Expand All @@ -63,18 +64,15 @@ int le_find(byte *addr, LENTRY *le, long *position, int mode)

low = 0;
hi = Nledger - 1;
if(mode == 1) addrlen = TXADDRLEN-12; else addrlen = TXADDRLEN;

while(low <= hi) {
mid = (hi + low) / 2;
if(fseek(Lefp, mid * sizeof(LENTRY), SEEK_SET) != 0)
{ Lerror = error("le_find(): fseek"); break; }
if(fread(le, 1, sizeof(LENTRY), Lefp) != sizeof(LENTRY))
{ Lerror = error("le_find(): fread"); break; }
if(mode == 1) {
cond = memcmp(addr, le->addr, TXADDRLEN-12);
} else {
cond = memcmp(addr, le->addr, TXADDRLEN);
}
cond = memcmp(addr, le->addr, addrlen);
if(cond == 0) {
if(position) *position = mid;
return 1; /* found target addr */
Expand Down
6 changes: 6 additions & 0 deletions src/makebx
@@ -0,0 +1,6 @@
#!/bin/sh
echo Making bx...
cc -DUNIXLIKE -DLONG64 -c crypto/hash/cpu/sha256.c
cc -DUNIXLIKE -DLONG64 -c algo/trigg/trigg.c
cc -DUNIXLIKE -DLONG64 -o bx bx.c trigg.o sha256.o
rm trigg.o sha256.o
4 changes: 2 additions & 2 deletions src/minertest.c
@@ -1,6 +1,6 @@

#define PATCHLEVEL 36
#define VERSIONSTR "36" /* as printable string */
#define PATCHLEVEL 37
#define VERSIONSTR "37" /* as printable string */

/* Include everything that we need */
#include "config.h"
Expand Down
4 changes: 2 additions & 2 deletions src/mochimo.c
Expand Up @@ -10,8 +10,8 @@
*/

/* build sequence */
#define PATCHLEVEL 36
#define VERSIONSTR "36" /* as printable string */
#define PATCHLEVEL 37
#define VERSIONSTR "37" /* as printable string */

/* Include everything that we need */
#include "config.h"
Expand Down
2 changes: 1 addition & 1 deletion src/mtxval.c
Expand Up @@ -55,7 +55,7 @@ int mtx_val(MTX *mtx, word32 *fee)
memcpy(ADDR_TAG_PTR(addr), mtx->dst[j].tag, ADDR_TAG_LEN);
mtx->zeros[j] = 0;
/* If dst[j] tag not found, put error code in zeros[] array. */
if(tag_find(addr, addr, NULL) != VEOK) mtx->zeros[j] = 1;
if(tag_find(addr, NULL, NULL) != VEOK) mtx->zeros[j] = 1;
}
} /* end for j */
/* Check tallies... */
Expand Down
45 changes: 22 additions & 23 deletions src/proof.c
Expand Up @@ -63,7 +63,7 @@ int past_weight(byte *weight, word32 lownum)
if(lownum >= cbnum) BAIL(1);
memcpy(weight, Weight, 32);
for( ; cbnum > lownum; cbnum--) {
if((cbnum & 0xff) == 0) continue;
if((cbnum & 0xff) == 0) continue; /* skip NG blocks */
if(readtf(&bts, cbnum, 1) != 1) BAIL(2);
sub_weight(weight, bts.difficulty[0]);
}
Expand All @@ -74,7 +74,8 @@ int past_weight(byte *weight, word32 lownum)
return message;
} /* end past_weight() */

#define INVALID_DIFFICULTY 256

#define INVALID_DIFF 256

/* Check the proof given from peer's tfile.dat in an OP_FOUND message.
* Return VEOK to run syncup(), else error code to ignore peer.
Expand All @@ -90,8 +91,6 @@ int checkproof(TX *tx, word32 *splitblock)
static word32 v24trigger[2] = { V24TRIGGER, 0 };
byte weight[32];

diff = INVALID_DIFFICULTY;

/* Check preconditions for proof scan: */
*splitblock = 0; /* invalid syncup() block */
if(get32(Cblocknum) < V23TRIGGER) goto allow;
Expand All @@ -108,13 +107,12 @@ int checkproof(TX *tx, word32 *splitblock)
count = readtf(&bts, tnum[0], 1); /* so read our tfile */
/* and compare it to theirs. */
if(count != 1 || memcmp(bt, &bts, sizeof(BTRAILER)) != 0) BAIL(1);
/* Compute our weight at their low block number. */
/* If we get here, our weights must also match at the first trailer. */
/* Compute our weight at their low block number less one. */
if(past_weight(weight, tnum[0] - 1) != VEOK) BAIL(2);
/* If we get here, our weights must also match at the first trailer
* and that weight is now in weight[].
*/

/* Verify peer's proof trailers in OP_FOUND TX. */
diff = INVALID_DIFF;
now = time(NULL);
prevnum = highblock - 1;
bt = (BTRAILER *) TRANBUFF(tx);
Expand All @@ -126,34 +124,35 @@ int checkproof(TX *tx, word32 *splitblock)
stime = get32(bt->stime);
time0 = get32(bt->time0);
difficulty = get32(bt->difficulty);
if(stime <= time0) BAIL(4); /* bad solve time sequence */
if(stime > (now + BCONFREQ)) BAIL(5); /* a future block is bad */
if(difficulty > 255) BAIL(4);
if(stime <= time0) BAIL(5); /* bad solve time sequence */
if(stime > (now + BCONFREQ)) BAIL(6); /* a future block is bad */
if(j != 0 && memcmp(bt->phash, (bt - 1)->bhash, HASHLEN)) BAIL(7);
if(bt->bnum[0] == 0) continue; /* skip NG block */
if(diff != INVALID_DIFFICULTY) {
if(difficulty != diff) BAIL(6); /* bad difficulty sequence */
if(memcmp(bt->phash, (bt - 1)->bhash, HASHLEN)) BAIL(7);
if(diff != INVALID_DIFF) {
if(difficulty != diff) BAIL(8); /* bad difficulty sequence */
}
/* stime must increase */
if(j != 0) {
if(stime <= (s = get32((bt - 1)->stime))) BAIL(8);
if(time0 != s) BAIL(9); /* time0 must == the previous stime */
/* stime must increase */
if(stime <= (s = get32((bt - 1)->stime))) BAIL(9);
if(time0 != s) BAIL(10); /* time0 must == the previous stime */
}
if(get32(bt->tcount) != 0) {
/* bt is not a pseudoblock so check work: */
if(cmp64(bt->bnum, v24trigger) > 0) { /* v2.4 */
if(peach(bt, difficulty, NULL, 1)) BAIL(10);
if(peach(bt, difficulty, NULL, 1)) BAIL(11);
} else { /* v2.3 and prior */
if(trigg_check(bt->mroot, difficulty, bt->bnum) == NULL) BAIL(11);
if(trigg_check(bt->mroot, difficulty, bt->bnum) == NULL) BAIL(12);
}
}
add_weight2(weight, difficulty); /* tally peer's chain weight */
/* Compute diff = next difficulty to check next peer trailer. */
diff = set_difficulty(difficulty, stime - time0, stime,
(byte *) tnum);
if(!Running) BAIL(12);
if(!Running) BAIL(13);
} /* end for j, bt -- proof trailers check */

if(memcmp(weight, tx->weight, 32)) BAIL(13); /* their weight is bad */
if(memcmp(weight, tx->weight, 32)) BAIL(14); /* their weight is bad */

/* Scan through trailer array to find where chain splits: splitblock */
bt = (BTRAILER *) TRANBUFF(tx);
Expand All @@ -166,11 +165,11 @@ int checkproof(TX *tx, word32 *splitblock)
*splitblock = tnum[0]; /* return first non-matching block number */
break;
}
if(!Running) BAIL(14);
if(!Running) BAIL(15);
/* trailers match -- continue scan */
} /* end for j, bt -- split detection */
if(j == 0) BAIL(15); /* never matched -- should not happen */
if(j >= NTFTX) BAIL(16); /* no split found -- should not happen */
if(j == 0) BAIL(16); /* never matched -- should not happen */
if(j >= NTFTX) BAIL(17); /* no split found -- should not happen */
allow:
if(Trace) plog("checkproof() splitblock = 0x%x", *splitblock);
return VEOK; /* allow syncup() to run */
Expand Down
4 changes: 1 addition & 3 deletions src/pval.c
Expand Up @@ -34,7 +34,7 @@ int pval(char *fname)
/* read trailer */
if(fseek(fp, -(sizeof(BTRAILER)), SEEK_END)) BAIL(6);
if(fread(&bt, sizeof(BTRAILER), 1, fp) != 1) BAIL(7);
fclose(fp); /* was opened by bval() */
fclose(fp);
fp = NULL;

/* check zeros */
Expand Down Expand Up @@ -80,8 +80,6 @@ int bridge(void)
FILE *fp = NULL;
int message;

if(Cblocknum[0] == 0xfe) BAIL(1); /* internal error */

if(Trace) plog("Making pblock.dat...");

fp = fopen("pblock.dat", "wb");
Expand Down
14 changes: 7 additions & 7 deletions src/server.c
Expand Up @@ -17,7 +17,7 @@
int server(void)
{
static time_t nsd_time; /* event timers */
static time_t bctime, mwtime, mqtime, sftime;
static time_t bctime, mwtime, mqtime, sftime, vtime;
static time_t ipltime;
static SOCKET lsd, nsd;
static NODE *np, node;
Expand All @@ -26,7 +26,6 @@ int server(void)
static pid_t pid; /* child pid */
static int lfd; /* for lock() */
static word32 hps; /* same as Hps in monitor.c */
static word32 bigwait;

Running = 1; /* globals are in data.c */

Expand All @@ -39,9 +38,9 @@ int server(void)
Utime = Ltime; /* for watchdog timer */
Watchdog = WATCHTIME + (rand2() % 600);
Bridgetime = Time0 + BRIDGE; /* pseudo-block timer */
bigwait = (60*60*3) + (rand2() % 10800); /* between 3 and 6 hours */
ipltime = Ltime + (rand2() % 300) + 10; /* ip list fetch time */
sftime = Ltime + (rand2() % 300) + 300; /* send_found() time */
vtime = Ltime + 4; /* Verisimility restart check time */

if((lsd = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
fatal("Cannot open listening socket.");
Expand Down Expand Up @@ -282,13 +281,14 @@ int server(void)
if(Monitor && !Bgflag) monitor();

if(Watchdog && (Ltime - Utime) >= Watchdog) {
if(Cblocknum[0] != 0xfe || (Ltime - Utime) >= bigwait) {
restart("watchdog");
}
restart("watchdog");
}

/* Check for restart signal from Verisimility every 4 seconds */
if((Ltime & 3) == 0 && exists("vstart.tmp")) restart("Verisimility");
if(Ltime >= vtime) {
if(exists("vstart.lck")) restart("Verisimility");
vtime += 4;
}

if(Ltime >= ipltime) {
refresh_ipl(); /* refresh ip list */
Expand Down
5 changes: 4 additions & 1 deletion src/syncup.c
Expand Up @@ -23,6 +23,7 @@ int syncup(word32 splitblock, byte *txcblock, word32 peerip)
NODE *np2;
time_t lasttime;

Insyncup = 1;
show("syncup");
if(Bcpid) { /* Wait for block constructor to exit... */
if(Trace) plog("syncup(): Waiting for bcon to exit...");
Expand Down Expand Up @@ -116,7 +117,7 @@ int syncup(word32 splitblock, byte *txcblock, word32 peerip)
if(Trace) plog("Download and update missing blocks from peer...");
put64(bnum, sblock);
for(j = 0; ; ) {
if(bnum[0] == 0) add64(bnum, One, bnum); /* don't get NG block */
if(bnum[0] == 0) add64(bnum, One, bnum); /* skip NG blocks */
sprintf(buff, "b%s.bc", bnum2hex(bnum));
if(j == 60) {
if(Trace) plog("syncup(): failed while downloading %s from %s",
Expand All @@ -143,6 +144,7 @@ int syncup(word32 splitblock, byte *txcblock, word32 peerip)
if(result) plog("syncup(): tfval() error: %d", result);
memcpy(Weight, tfweight, HASHLEN);
if(result == 0) plog("syncup() is good!");
Insyncup = 0;
return VEOK;

badsyncup:
Expand All @@ -156,5 +158,6 @@ int syncup(word32 splitblock, byte *txcblock, word32 peerip)
reset_difficulty(NULL, Bcdir); /* reset Difficulty and others */
memcpy(Weight, saveweight, HASHLEN);
le_open("ledger.dat", "rb");
Insyncup = 0;
return VEOK;
} /* end syncup() */

0 comments on commit ad45c88

Please sign in to comment.