コード例 #1
0
ファイル: iguana_accept.c プロジェクト: msareem05/SuperNET
int32_t iguana_headerget(struct iguana_info *coin,uint8_t *serialized,int32_t maxsize,struct iguana_block *block)
{
    bits256 checkhash2; struct iguana_msgblock msgB; int32_t len = 0;
    iguana_blockunconv(coin->chain->zcash,coin->chain->auxpow,&msgB,block,1);
    if ( (len= iguana_rwblock(coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,1,&checkhash2,&serialized[sizeof(struct iguana_msghdr)],&msgB,(int32_t)(maxsize-sizeof(struct iguana_msghdr)))) < 0 )
        return(-1);
    if ( bits256_cmp(checkhash2,block->RO.hash2) != 0 )
    {
        char str[65],str2[65];
        printf("iguana_peerhdrrequest blockhash.%d error (%s) vs (%s)\n",block->height,bits256_str(str,checkhash2),bits256_str(str2,block->RO.hash2));
        return(-1);
    }
    return(len);
}
コード例 #2
0
ファイル: iguana_tx.c プロジェクト: kashifali00/SuperNet
int32_t iguana_peerblockrequest(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *blockspace,int32_t max,struct iguana_peer *addr,bits256 hash2,int32_t validatesigs)
{
#if defined(_M_X64)
	/*
	* because we have no choice but to access the memory address
	* we need 64bit to correctly hold 64bit memory address, thus changing
	* to uint64_t instead of long in win x64
	* @author - [email protected]
	*/
	struct iguana_txid *tx, T; bits256 checktxid; int32_t i, len, total, bundlei = -2; struct iguana_block *block; struct iguana_msgzblock zmsgB; bits256 *tree, checkhash2, merkle_root; struct iguana_bundle *bp = 0; uint64_t tmp; char str[65]; struct iguana_ramchaindata *rdata;
#else
    struct iguana_txid *tx,T; bits256 checktxid; int32_t i,len,total,bundlei=-2; struct iguana_block *block; struct iguana_msgzblock zmsgB; bits256 *tree,checkhash2,merkle_root; struct iguana_bundle *bp=0; long tmp; char str[65]; struct iguana_ramchaindata *rdata;
#endif
    if ( (bp= iguana_bundlefind(coin,&bp,&bundlei,hash2)) != 0 && bundlei >= 0 && bundlei < bp->n )
    {
        if ( (rdata= bp->ramchain.H.data) == 0 )//&& bp == coin->current )
        {
            //printf("iguana_peerblockrequest no ramchain data [%d] use RTcache\n",bp->hdrsi);
            //rdata = coin->RTramchain.H.data;
            return(-1);
        }
        if ( (block= bp->blocks[bundlei]) != 0 && rdata != 0 )
        {
            iguana_blockunconv(coin->chain->zcash,coin->chain->auxpow,&zmsgB,(void *)block,0);
            zmsgB.txn_count = block->RO.txn_count;
            total = iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,1,&checkhash2,&blockspace[sizeof(struct iguana_msghdr) + 0],&zmsgB,max);
            if ( bits256_cmp(checkhash2,block->RO.hash2) != 0 )
            {
                //static int counter;
                //if ( counter++ < 100 )
                    printf("iguana_peerblockrequest: blockhash mismatch ht.%d\n",bp->bundleheight+bundlei);
                return(-1);
            }
            for (i=0; i<block->RO.txn_count; i++)
            {
                if ( (tx= iguana_blocktx(coin,&T,block,i)) != 0 )
                {
                    //printf("ht.%d [%d:%d] txi.%d i.%d o.%d %s\n",block->height,block->hdrsi,block->bundlei,i,tx->numvins,tx->numvouts,bits256_str(str,tx->txid));
                    if ( (len= iguana_ramtxbytes(coin,&blockspace[sizeof(struct iguana_msghdr) + total],max - total,&checktxid,tx,block->height,0,0,validatesigs)) > 0 )//&& bits256_cmp(checktxid,T.txid) == 0 )
                        total += len;
                    else
                    {
                        static uint32_t counter;
                        char str[65],str2[65];
                        if ( counter++ < 100 )
                        {
                            for (i=0; i<len; i++)
                                printf("%02x",blockspace[sizeof(struct iguana_msghdr)+i]);
                            printf(" len.%d error getting txi.%d [%d:%d] cmp.%s %s\n",len,i,bp->hdrsi,bundlei,bits256_str(str,checktxid),bits256_str(str2,T.txid));
                        }
                        break;
                    }
                }
                else
                {
                    printf("%s null tx error getting txi.%d [%d:%d]\n",coin->symbol,i,bp->hdrsi,bundlei);
                    break;
                }
            }
            if ( i == block->RO.txn_count )
            {
#if defined(_M_X64)
				/*
				* because we have no choice but to access the memory address
				* we need 64bit to correctly hold 64bit memory address, thus changing
				* to uint64_t instead of long in win x64
				* @author - [email protected]
				*/
				tmp = (uint64_t)&blockspace[sizeof(struct iguana_msghdr) + total + sizeof(bits256)];
#else
                tmp = (long)&blockspace[sizeof(struct iguana_msghdr) + total + sizeof(bits256)];
#endif
                tmp &= ~(sizeof(bits256) - 1);
                tree = (void *)tmp;
                for (i=0; i<block->RO.txn_count; i++)
                {
                    if ( (tx= iguana_blocktx(coin,&T,block,i)) != 0 )
                        tree[i] = T.txid;
                    else break;
                }
                if ( i == block->RO.txn_count )
                {
                    merkle_root = iguana_merkle(tree,block->RO.txn_count);
                    if ( bits256_cmp(merkle_root,block->RO.merkle_root) == 0 )
                    {
                        if ( addr != 0 && addr->lastsent != block->height )
                        {
                            addr->lastsent = block->height;
                            printf("Sendlen.%d block.%d %s to %s\n",total,block->height,bits256_str(str,block->RO.hash2),addr->ipaddr);
                            if ( 0 )
                            {
                                struct iguana_txblock txdata; int32_t checklen; static struct OS_memspace RAWMEM;
                                if ( RAWMEM.ptr == 0 )
                                    iguana_meminit(&RAWMEM,addr->ipaddr,0,IGUANA_MAXPACKETSIZE * 2,0);
                                else iguana_memreset(&RAWMEM);
                                memset(&txdata,0,sizeof(txdata));
                                int32_t i;
                                for (i=0; i<total; i++)
                                {
                                    if ( i == 81 )
                                        printf(" ");
                                    printf("%02x",blockspace[i + sizeof(struct iguana_msghdr)]);
                                }
                                printf(" blocksize.%d\n",total);
                                for (i=0; i<16; i++)
                                    printf("%02x",blockspace[i + sizeof(struct iguana_msghdr)+81]);
                                printf(" txhdr\n");
                                if ( (checklen= iguana_gentxarray(myinfo,coin,&RAWMEM,&txdata,&checklen,&blockspace[sizeof(struct iguana_msghdr)],total)) != total && checklen != total-1 )
                                    printf("Error reconstructing txarray checklen.%d total.%d\n",checklen,total);
                            }
                            return(iguana_queue_send(addr,0,blockspace,"block",total));
                        }
                        else
                        {
                            //printf("validated.[%d:%d] len.%d\n",bp->hdrsi,bundlei,total);
                            return(total);
                        }
                    } else printf("iguana_peerblockrequest: %s error %s merkle cmp tx.[%d] for ht.%d\n",coin->symbol,bits256_str(str,block->RO.hash2),i,bp->bundleheight+bundlei);
                } else printf("iguana_peerblockrequest: error merkle verify tx.[%d] for ht.%d\n",i,bp->bundleheight+bundlei);
            }
            else
            {
                static uint32_t counter;
                if ( counter++ < 10 )
                    printf("%s iguana_peerblockrequest: error getting tx.[%d] for ht.%d block.%p main.%d ht.%d\n",coin->symbol,i,bp->bundleheight+bundlei,block,block!=0?block->mainchain:-1,block!=0?block->height:-1);
            }
        }
        else
        {
            if ( coin->virtualchain != 0 )
                ;
            /*if ( block != 0 )
                printf("iguana_peerblockrequest: block.%p ht.%d mainchain.%d [%d:%d] from %s bp.%p rdata.%p\n",block,block->height,block->mainchain,bp->hdrsi,bundlei,addr!=0?addr->ipaddr:"local",bp,bp!=0?rdata:0);
            else printf("iguana_peerblockrequest: block.%p [%d:%d]\n",block,bp->hdrsi,bundlei);*/
        }
    } //else printf("iguana_peerblockrequest: cant find %s\n",bits256_str(str,hash2));
    return(-1);
}