Skip to content

Commit

Permalink
Merge pull request #598 from DeckerSU/patch-refactor-old-code
Browse files Browse the repository at this point in the history
refactor old code (pax, kv, ratification, etc.)
  • Loading branch information
ca333 authored Nov 3, 2023
2 parents bac0096 + 2d5f55b commit 3212c3c
Show file tree
Hide file tree
Showing 4 changed files with 714 additions and 74 deletions.
3 changes: 2 additions & 1 deletion src/Makefile.ktest.include
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ bin_PROGRAMS += komodo-test
test-komodo/test_haraka_removal.cpp \
test-komodo/test_miner.cpp \
test-komodo/test_oldhash_removal.cpp \
test-komodo/test_kmd_feat.cpp
test-komodo/test_kmd_feat.cpp \
test-komodo/test_legacy_events.cpp

if TARGET_WINDOWS
komodo_test_SOURCES += test-komodo/komodo-test-res.rc
Expand Down
35 changes: 11 additions & 24 deletions src/assetchains.old
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,14 @@ set -x
delay=60
source pubkey.txt
echo $pubkey

./komodod -pubkey=$pubkey -ac_name=BET -ac_supply=999999 -addnode=95.213.238.98 $1 &
./komodod -pubkey=$pubkey -ac_name=BOTS -ac_supply=999999 -addnode=95.213.238.98 $1 &
./komodod -pubkey=$pubkey -ac_name=CCL -ac_supply=200000000 -ac_end=1 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=142.93.136.89 -addnode=195.201.22.89 $1 &
./komodod -pubkey=$pubkey -ac_name=CLC -ac_supply=99000000 -ac_reward=50000000 -ac_perc=100000000 -ac_founders=1 -ac_cc=45 -ac_public=1 -ac_snapshot=1440 -ac_pubkey=02df9bda7bfe2bcaa938b29a399fb0ba58cfb6cc3ddc0001062a600f60a8237ad9 -addnode=node.cryptocollider.com -ac_adaptivepow=6 $1 &
./komodod -pubkey=$pubkey -ac_name=CRYPTO -ac_supply=999999 -addnode=95.213.238.98 $1 &
./komodod -pubkey=$pubkey -ac_name=DEX -ac_supply=999999 -addnode=95.213.238.98 $1 &
./komodod -pubkey=$pubkey -ac_name=GLEEC -ac_supply=210000000 -ac_public=1 -ac_staked=100 -addnode=95.217.161.126 $1 &
./komodod -pubkey=$pubkey -ac_name=HODL -ac_supply=9999999 -addnode=95.213.238.98 $1 &
./komodod -pubkey=$pubkey -ac_name=ILN -ac_supply=10000000000 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=51.75.122.83 $1 &
./komodod -pubkey=$pubkey -ac_name=JUMBLR -ac_supply=999999 -addnode=95.213.238.98 $1 &
./komodod -pubkey=$pubkey -ac_name=KOIN -ac_supply=125000000 -addnode=3.0.32.10 $1 &
./komodod -pubkey=$pubkey -ac_name=MESH -ac_supply=1000007 -ac_ccactivate=320000 -addnode=95.213.238.98 $1 &
./komodod -pubkey=$pubkey -ac_name=MGW -ac_supply=999999 -addnode=95.213.238.98 $1 &
./komodod -pubkey=$pubkey -ac_name=MORTY -ac_supply=90000000000 -ac_reward=100000000 -ac_cc=3 -ac_staked=10 -addnode=95.217.44.58 -addnode=138.201.136.145 $1 &
./komodod -pubkey=$pubkey -ac_name=MSHARK -ac_supply=1400000 -addnode=95.213.238.98 $1 &
./komodod -pubkey=$pubkey -ac_name=NINJA -ac_supply=100000000 -addnode=95.213.238.98 $1 &
./komodod -pubkey=$pubkey -ac_name=PANGEA -ac_supply=999999 -addnode=95.213.238.98 $1 &
./komodod -pubkey=$pubkey -ac_name=PIRATE -ac_supply=0 -ac_reward=25600000000 -ac_halving=77777 -ac_private=1 -addnode=88.99.212.81 $1 &
./komodod -pubkey=$pubkey -ac_name=REVS -ac_supply=1300000 -addnode=95.213.238.98 $1 &
./komodod -pubkey=$pubkey -ac_name=RICK -ac_supply=90000000000 -ac_reward=100000000 -ac_cc=3 -ac_staked=10 -addnode=95.217.44.58 -addnode=138.201.136.145 $1 &
./komodod -pubkey=$pubkey -ac_name=SUPERNET -ac_supply=816061 -addnode=95.213.238.98 $1 &
./komodod -pubkey=$pubkey -ac_name=THC -ac_supply=251253103 -ac_reward=360000000,300000000,240000000,180000000,150000000,90000000,0 -ac_staked=100 -ac_eras=7 -ac_end=500001,1000001,1500001,2000001,2500001,4500001,0 -ac_perc=233333333 -ac_cc=2 -ac_ccenable=229,236,240 -ac_script=2ea22c8020987fad30df055db6fd922c3a57e55d76601229ed3da3b31340112e773df3d0d28103120c008203000401ccb8 -ac_founders=150 -ac_cbmaturity=1 -ac_sapling=1 -addnode=157.230.45.184 -addnode=165.22.52.123 -earlytxid=7e4a76259e99c9379551389e9f757fc5f46c33ae922a8644dc2b187af2a6adc1 $1 &
./komodod -pubkey=$pubkey -ac_name=ZILLA -ac_supply=11000000 -ac_sapling=5000000 -addnode=51.68.215.104 $1 &
komodod -pubkey=$pubkey -ac_name=CCL -ac_supply=200000000 -ac_end=1 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=142.93.136.89 -addnode=195.201.22.89 -addnode=209.222.101.247 -addnode=103.195.100.32 $1 &
komodod -pubkey=$pubkey -ac_name=CLC -ac_supply=99000000 -ac_reward=50000000 -ac_perc=100000000 -ac_founders=1 -ac_cc=45 -ac_public=1 -ac_snapshot=1440 -ac_pubkey=02df9bda7bfe2bcaa938b29a399fb0ba58cfb6cc3ddc0001062a600f60a8237ad9 -addnode=node.cryptocollider.com -ac_adaptivepow=6 -addnode=209.222.101.247 -addnode=103.195.100.32 $1 &
komodod -pubkey=$pubkey -ac_name=DOC -ac_supply=90000000000 -ac_reward=100000000 -ac_cc=3 -ac_staked=10 -addnode=65.21.77.109 -addnode=65.21.51.47 -addnode=209.222.101.247 -addnode=103.195.100.32 $1 &
komodod -pubkey=$pubkey -ac_name=GLEEC -ac_supply=210000000 -ac_public=1 -ac_staked=100 -addnode=95.217.161.126 -addnode=209.222.101.247 -addnode=103.195.100.32 $1 &
komodod -pubkey=$pubkey -ac_name=ILN -ac_supply=10000000000 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=51.75.122.83 -addnode=209.222.101.247 -addnode=103.195.100.32 $1 &
komodod -pubkey=$pubkey -ac_name=KOIN -ac_supply=125000000 -addnode=3.0.32.10 -addnode=209.222.101.247 -addnode=103.195.100.32 $1 &
komodod -pubkey=$pubkey -ac_name=MARTY -ac_supply=90000000000 -ac_reward=100000000 -ac_cc=3 -ac_staked=10 -addnode=65.21.77.109 -addnode=65.21.51.47 -addnode=209.222.101.247 -addnode=103.195.100.32 $1 &
komodod -pubkey=$pubkey -ac_name=NINJA -ac_supply=100000000 -addnode=95.213.238.98 -addnode=209.222.101.247 -addnode=103.195.100.32 $1 &
komodod -pubkey=$pubkey -ac_name=PIRATE -ac_supply=0 -ac_reward=25600000000 -ac_halving=77777 -ac_private=1 -addnode=88.99.212.81 -addnode=209.222.101.247 -addnode=103.195.100.32 $1 &
komodod -pubkey=$pubkey -ac_name=SUPERNET -ac_supply=816061 -addnode=95.213.238.98 -addnode=209.222.101.247 -addnode=103.195.100.32 $1 &
komodod -pubkey=$pubkey -ac_name=THC -ac_supply=251253103 -ac_reward=360000000,300000000,240000000,180000000,150000000,90000000,0 -ac_staked=100 -ac_eras=7 -ac_end=500001,1000001,1500001,2000001,2500001,4500001,0 -ac_perc=233333333 -ac_cc=2 -ac_ccenable=229,236,240 -ac_script=2ea22c8020987fad30df055db6fd922c3a57e55d76601229ed3da3b31340112e773df3d0d28103120c008203000401ccb8 -ac_founders=150 -ac_cbmaturity=1 -ac_sapling=1 -addnode=157.230.45.184 -addnode=165.22.52.123 -earlytxid=7e4a76259e99c9379551389e9f757fc5f46c33ae922a8644dc2b187af2a6adc1 -addnode=209.222.101.247 -addnode=103.195.100.32 $1 &
147 changes: 98 additions & 49 deletions src/komodo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,34 @@ int32_t komodo_validate_chain(uint256 srchash,int32_t notarized_height)
} else return(1);
}

namespace {
bool CheckChainNameInScript(uint8_t* scriptbuf, int32_t scriptlen, size_t offsetInScript)
{
std::string chainPattern = chainName.ToString();
size_t chainPatternSize = chainPattern.size();

if (offsetInScript + chainPatternSize < scriptlen) {
if (std::equal(chainPattern.begin(), chainPattern.end(), &scriptbuf[offsetInScript]) && scriptbuf[offsetInScript + chainPatternSize] == '\0') {
return true;
}
}
return false;
}

std::string GetChainNameFromScript(uint8_t* scriptbuf, int32_t scriptlen, size_t offsetInScript)
{
std::string chainPattern = "";
const size_t maxChainName = sizeof(komodo_ccdata::symbol);

while (offsetInScript < scriptlen && scriptbuf[offsetInScript] != '\0' && chainPattern.size() < maxChainName) {
chainPattern.push_back(scriptbuf[offsetInScript]);
++offsetInScript;
}

return chainPattern;
}
}

int32_t komodo_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notaryid,uint8_t *scriptbuf,
int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,
int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value,int32_t notarized,
Expand Down Expand Up @@ -399,42 +427,70 @@ int32_t komodo_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notar
{
struct komodo_ccdata ccdata; struct komodo_ccdataMoMoM MoMoMdata;
int32_t validated = 0,nameoffset,opoffset = 0;
if ( (opretlen= scriptbuf[len++]) == 0x4c )
opretlen = scriptbuf[len++];
else if ( opretlen == 0x4d )
{
opretlen = scriptbuf[len++];
opretlen += (scriptbuf[len++] << 8);

if (scriptlen - len < 1)
return notaryid;

uint8_t opcode = scriptbuf[len++];

if (opcode <= OP_PUSHDATA4) {
opretlen = 0;
if (opcode < OP_PUSHDATA1) {
opretlen = opcode;
} else if (opcode == OP_PUSHDATA1) {
if (scriptlen - len < 1)
return notaryid;
opretlen = scriptbuf[len++];
} else if (opcode == OP_PUSHDATA2) {
if (scriptlen - len < 2)
return notaryid;
uint16_t x;
memcpy((char*)&x, &scriptbuf[len], 2);
opretlen = le16toh(x);
len += 2;
} else if (opcode == OP_PUSHDATA4) {
if (scriptlen - len < 4)
return notaryid;
uint32_t x;
memcpy((char*)&x, &scriptbuf[len], 4);
opretlen = le32toh(x);
len += 4;
}
} else {
return notaryid;
}

if (scriptlen - len < 0 || (unsigned int)(scriptlen - len) < opretlen)
return notaryid;

if (opretlen < 34) // Stop processing of OP_RETURNs that do not contain significant data,
return notaryid; // such as a 33-byte staking opret or a 32-byte notary proof in a mined block.

opoffset = len;

matched = 0;
if ( chainName.isKMD() )
{
if ( strcmp("KMD",(char *)&scriptbuf[len+32 * 2 + 4]) == 0 )
matched = 1;
}
else
{
if ( scriptbuf[len] == 'K' )
{
//fprintf(stderr,"i.%d j.%d KV OPRET len.%d %.8f\n",i,j,opretlen,dstr(value));
komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,value,&scriptbuf[len],opretlen,j,zero,0);
return(-1);
}
if ( strcmp(chainName.symbol().c_str(),(char *)&scriptbuf[len+32*2+4]) == 0 )
matched = 1;

if (CheckChainNameInScript(scriptbuf, scriptlen, len + 32 * 2 + 4)) {
matched = 1;
}

offset = 32 * (1 + matched) + 4;
nameoffset = (int32_t)strlen((char *)&scriptbuf[len+offset]);

std::string fromScriptChainName = GetChainNameFromScript(scriptbuf, scriptlen, len + offset);
if (fromScriptChainName.empty())
return notaryid;

nameoffset = fromScriptChainName.size();
nameoffset++;
memset(&ccdata,0,sizeof(ccdata));
strncpy(ccdata.symbol,(char *)&scriptbuf[len+offset],sizeof(ccdata.symbol));
std::copy_n(fromScriptChainName.begin(), std::min(fromScriptChainName.size(), sizeof(ccdata.symbol)), ccdata.symbol);

if ( j == 1 && opretlen >= len+offset-opoffset )
{
memset(&MoMoMdata,0,sizeof(MoMoMdata));
if ( matched == 0 && signedmask != 0 && bitweight(signedmask) >= KOMODO_MINRATIFY )
notarized = 1;
if ( strcmp("PIZZA",ccdata.symbol) == 0 || strncmp("TXSCL",ccdata.symbol,5) == 0 || strcmp("BEER",ccdata.symbol) == 0)
if (fromScriptChainName == "PIZZA" || fromScriptChainName == "BEER" || fromScriptChainName.substr(0, 5) == "TXSCL")
notarized = 1;
len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&srchash);
len += iguana_rwnum(0,&scriptbuf[len],sizeof(*notarizedheightp),(uint8_t *)notarizedheightp);
Expand Down Expand Up @@ -541,13 +597,6 @@ int32_t komodo_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notar
fwrite(&signedmask,1,sizeof(signedmask),signedfp);
fflush(signedfp);
}
if ( opretlen > len && scriptbuf[len] == 'A' )
{
//for (i=0; i<opretlen-len; i++)
// printf("%02x",scriptbuf[len+i]);
//printf(" Found extradata.[%d] %d - %d\n",opretlen-len,opretlen,len);
komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,value,&scriptbuf[len],opretlen-len+4+3+(scriptbuf[1] == 0x4d),j,zero,0);
}
}
}
} else if ( opretlen != 149 && height > 600000 && matched != 0 )
Expand All @@ -562,7 +611,7 @@ int32_t komodo_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notar
}
else if ( matched != 0 )
{
if ( opretlen >= 32*2+4 && strcmp(chainName.ToString().c_str(),(char *)&scriptbuf[len+32*2+4]) == 0 )
if ( opretlen >= 32*2+4 && CheckChainNameInScript(scriptbuf, scriptlen, len + 32 * 2 + 4) )
{
for (k=0; k<32; k++)
if ( scriptbuf[len+k] != 0 )
Expand All @@ -573,9 +622,6 @@ int32_t komodo_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notar
printf("ISRATIFICATION (%s)\n",(char *)&scriptbuf[len+32*2+4]);
}
}

if ( *isratificationp == 0 && (signedmask != 0 || (scriptbuf[len] != 'X' && scriptbuf[len] != 'A')) ) // && scriptbuf[len] != 'I')
komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,value,&scriptbuf[len],opretlen,j,zero,0);
}
}
return(notaryid);
Expand Down Expand Up @@ -785,25 +831,28 @@ int32_t komodo_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block)
}
if ( specialtx != 0 && isratification != 0 && numvouts > 2 )
{
numvalid = 0;
memset(pubkeys,0,sizeof(pubkeys));
for (j=1; j<numvouts-1; j++)
if (chainName.isKMD() && height < 100000)
{
len = block.vtx[i].vout[j].scriptPubKey.size();
if ( len >= sizeof(uint32_t) && len <= sizeof(scriptbuf) )
numvalid = 0;
memset(pubkeys,0,sizeof(pubkeys));
for (j=1; j<numvouts-1; j++)
{
memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len);
if ( len == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac )
len = block.vtx[i].vout[j].scriptPubKey.size();
if ( len >= sizeof(uint32_t) && len <= sizeof(scriptbuf) )
{
memcpy(pubkeys[numvalid++],scriptbuf+1,33);
for (k=0; k<33; k++)
printf("%02x",scriptbuf[k+1]);
printf(" <- new notary.[%d]\n",j-1);
memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len);
if ( len == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac )
{
if (numvalid < 64) {
memcpy(pubkeys[numvalid++],scriptbuf+1,33);
for (k=0; k<33; k++)
printf("%02x",scriptbuf[k+1]);
printf(" <- new notary.[%d]\n",j-1);
}
}
}
}
}
if ( !chainName.isKMD() || height < 100000 )
{

if ( ((signedmask & 1) != 0 && numvalid >= KOMODO_MINRATIFY) || bitweight(signedmask) > (numnotaries/3) )
{
memset(&txhash,0,sizeof(txhash));
Expand Down
Loading

0 comments on commit 3212c3c

Please sign in to comment.