Skip to content

Commit

Permalink
Available field outside data object and avoiding protocol checks in c…
Browse files Browse the repository at this point in the history
…ase of chunk parma upgrades
  • Loading branch information
mike31 committed Jun 5, 2018
1 parent b3e7bb7 commit 12cc667
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 28 deletions.
30 changes: 23 additions & 7 deletions src/protocol/multichainscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2354,7 +2354,7 @@ int mc_Script::SetDataFormat(const uint32_t format)
return MC_ERR_NOERROR;
}

int mc_Script::GetChunkDef(uint32_t *format,unsigned char** hashes,int *chunk_count,int64_t *total_size)
int mc_Script::GetChunkDef(uint32_t *format,unsigned char** hashes,int *chunk_count,int64_t *total_size,int check_sizes)
{
unsigned char *ptr;
unsigned char *ptrEnd;
Expand Down Expand Up @@ -2431,9 +2431,12 @@ int mc_Script::GetChunkDef(uint32_t *format,unsigned char** hashes,int *chunk_co

ptr+=shift;

if(count > MAX_CHUNK_COUNT)
if(check_sizes)
{
return MC_ERR_ERROR_IN_SCRIPT;
if(count > MAX_CHUNK_COUNT)
{
return MC_ERR_ERROR_IN_SCRIPT;
}
}

if(chunk_count)
Expand All @@ -2460,9 +2463,12 @@ int mc_Script::GetChunkDef(uint32_t *format,unsigned char** hashes,int *chunk_co
return MC_ERR_ERROR_IN_SCRIPT;
}

if(size > MAX_CHUNK_SIZE)
if(check_sizes)
{
return MC_ERR_ERROR_IN_SCRIPT;
if(size > MAX_CHUNK_SIZE)
{
return MC_ERR_ERROR_IN_SCRIPT;
}
}

ptr+=shift;
Expand All @@ -2483,6 +2489,11 @@ int mc_Script::GetChunkDef(uint32_t *format,unsigned char** hashes,int *chunk_co
return MC_ERR_NOERROR;
}

int mc_Script::GetChunkDef(uint32_t *format,unsigned char** hashes,int *chunk_count,int64_t *total_size)
{
return GetChunkDef(format,hashes,chunk_count,total_size,0);
}

int mc_Script::SetChunkDefHeader(const uint32_t format,int chunk_count)
{
int err,shift;
Expand Down Expand Up @@ -2537,7 +2548,7 @@ int mc_Script::ExtractAndDeleteDataFormat(uint32_t *format)
return ExtractAndDeleteDataFormat(format,NULL,NULL,NULL);
}

int mc_Script::ExtractAndDeleteDataFormat(uint32_t *format,unsigned char** hashes,int *chunk_count,int64_t *total_size)
int mc_Script::ExtractAndDeleteDataFormat(uint32_t *format,unsigned char** hashes,int *chunk_count,int64_t *total_size,int check_sizes)
{
int elem,err;

Expand Down Expand Up @@ -2601,7 +2612,7 @@ int mc_Script::ExtractAndDeleteDataFormat(uint32_t *format,unsigned char** hashe
elem=m_NumElements-2;

SetElement(elem);
while( (elem >= 0 ) && ((err=GetChunkDef(format,hashes,chunk_count,total_size)) == MC_ERR_NOERROR) )
while( (elem >= 0 ) && ((err=GetChunkDef(format,hashes,chunk_count,total_size,check_sizes)) == MC_ERR_NOERROR) )
{
m_Restrictions |= MC_ENT_ENTITY_RESTRICTION_OFFCHAIN;
DeleteElement(elem);
Expand Down Expand Up @@ -2632,6 +2643,11 @@ int mc_Script::ExtractAndDeleteDataFormat(uint32_t *format,unsigned char** hashe
return MC_ERR_NOERROR;
}

int mc_Script::ExtractAndDeleteDataFormat(uint32_t *format,unsigned char** hashes,int *chunk_count,int64_t *total_size)
{
return ExtractAndDeleteDataFormat(format,hashes,chunk_count,total_size,0);
}

int mc_Script::DeleteDuplicatesInRange(int from,int to)
{
int *len0,*len1,*len2,*len3,*len4;
Expand Down
2 changes: 2 additions & 0 deletions src/protocol/multichainscript.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ typedef struct mc_Script
int SetDataFormat(const uint32_t format);

int GetChunkDef(uint32_t *format,unsigned char** hashes,int *chunk_count,int64_t *total_size);
int GetChunkDef(uint32_t *format,unsigned char** hashes,int *chunk_count,int64_t *total_size,int check_sizes);
int SetChunkDefHeader(const uint32_t format,int chunk_count);
int SetChunkDefHash(unsigned char *hash,int size);

int ExtractAndDeleteDataFormat(uint32_t *format);
int ExtractAndDeleteDataFormat(uint32_t *format,unsigned char** hashes,int *chunk_count,int64_t *total_size);
int ExtractAndDeleteDataFormat(uint32_t *format,unsigned char** hashes,int *chunk_count,int64_t *total_size,int check_sizes);
int DeleteDuplicatesInRange(int from,int to);


Expand Down
4 changes: 1 addition & 3 deletions src/protocol/multichaintx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ void MultiChainTransaction_FillAdminPermissionsBeforeTx(const CTransaction& tx,

bool MultiChainTransaction_VerifyAndDeleteDataFormatElements(string& reason,int64_t *total_size)
{
if(mc_gState->m_TmpScript->ExtractAndDeleteDataFormat(NULL,NULL,NULL,total_size))
if(mc_gState->m_TmpScript->ExtractAndDeleteDataFormat(NULL,NULL,NULL,total_size,1))
{
reason="Error in data format script";
return false;
Expand All @@ -590,7 +590,6 @@ bool MultiChainTransaction_CheckOpReturnScript(const CTransaction& tx,
int64_t total_offchain_size;

total_offchain_size=0;
// mc_gState->m_TmpScript->ExtractAndDeleteDataFormat(NULL); // Format scripts are eliminated for protocol checks
if(!MultiChainTransaction_VerifyAndDeleteDataFormatElements(reason,&total_offchain_size))
{
return false;
Expand Down Expand Up @@ -858,7 +857,6 @@ bool MultiChainTransaction_CheckEntityItem(const CTransaction& tx,
unsigned char short_txid[MC_AST_SHORT_TXID_SIZE];
mc_EntityDetails entity;

// mc_gState->m_TmpScript->ExtractAndDeleteDataFormat(NULL); // Format scripts are eliminated for protocol checks
if(!MultiChainTransaction_VerifyAndDeleteDataFormatElements(reason,NULL))
{
return false;
Expand Down
53 changes: 35 additions & 18 deletions src/rpc/rpcutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1028,12 +1028,13 @@ uint32_t GetFormattedData(mc_Script *lpScript,const unsigned char **elem,int64_t
return status;
}

/*
if(size > MAX_CHUNK_SIZE)
{
status |= MC_OST_ERROR_SCRIPT;
return status;
}

*/
ptr+=shift;
if(pwalletTxsMain->m_ChunkDB->GetChunkDef(&chunk_def,ptr,NULL,NULL,-1) == MC_ERR_NOERROR)
{
Expand Down Expand Up @@ -1119,19 +1120,10 @@ string OffChainError(uint32_t status,int *errorCode)
return error_str;
}

Value OpReturnFormatEntry(const unsigned char *elem,int64_t elem_size,uint256 txid, int vout, uint32_t format, string *format_text_out,uint32_t status)
bool AvailableFromStatus(uint32_t status)
{
string metadata="";
Object metadata_object;
Value metadata_value;
bool available;//,offchain;
string status_str,error_str;
int errorCode;
int err;

bool available;
available=false;
// offchain=true;
status_str="";

if( status == MC_OST_UNDEFINED )
{
Expand All @@ -1140,16 +1132,13 @@ Value OpReturnFormatEntry(const unsigned char *elem,int64_t elem_size,uint256 tx

if( (status & MC_OST_STORAGE_MASK) == MC_OST_ON_CHAIN )
{
status_str="on-chain";
available=true;
// offchain=false;
}

if( (status & MC_OST_STORAGE_MASK) == MC_OST_OFF_CHAIN )
{
if( (status & MC_OST_STATUS_MASK) == MC_OST_RETRIEVED )
{
status_str="retrieved";
available=true;
}

Expand All @@ -1159,6 +1148,21 @@ Value OpReturnFormatEntry(const unsigned char *elem,int64_t elem_size,uint256 tx
}
}

return available;
}

Value OpReturnFormatEntry(const unsigned char *elem,int64_t elem_size,uint256 txid, int vout, uint32_t format, string *format_text_out,uint32_t status)
{
string metadata="";
Object metadata_object;
Value metadata_value;
bool available;//,offchain;
string error_str;
int errorCode;
int err;

available=AvailableFromStatus(status);

if(status & MC_OST_ERROR_MASK)
{
error_str=OffChainError(status,&errorCode);
Expand Down Expand Up @@ -1215,16 +1219,16 @@ Value OpReturnFormatEntry(const unsigned char *elem,int64_t elem_size,uint256 tx
metadata_object.push_back(Pair("vout", vout));
metadata_object.push_back(Pair("format", OpReturnFormatToText(format)));
metadata_object.push_back(Pair("size", elem_size));
// metadata_object.push_back(Pair("offchain", offchain));
/*
if( ( status & MC_OST_CONTROL_NO_DATA ) == 0)
{
if(status & MC_OST_ERROR_MASK)
{
metadata_object.push_back(Pair("error", error_str));
}
metadata_object.push_back(Pair("available", available));
// metadata_object.push_back(Pair("status", status_str));
}
*/
return metadata_object;
}

Expand Down Expand Up @@ -1396,7 +1400,20 @@ Value DataItemEntry(const CTransaction& tx,int n,set <uint256>& already_seen,uin
{
entry.push_back(Pair("key", keys[0]));
}
entry.push_back(Pair("data", format_item_value));
entry.push_back(Pair("data", format_item_value));

if( ( retrieve_status & MC_OST_CONTROL_NO_DATA ) == 0)
{
if(retrieve_status & MC_OST_ERROR_MASK)
{
string error_str;
int errorCode;
error_str=OffChainError(retrieve_status,&errorCode);
entry.push_back(Pair("error", error_str));
}
entry.push_back(Pair("available", AvailableFromStatus(retrieve_status)));
}

entry.push_back(Pair("offchain", (retrieve_status & MC_OST_STORAGE_MASK) == MC_OST_OFF_CHAIN));
if(retrieve_status & MC_OST_CONTROL_NO_DATA)
{
Expand Down
1 change: 1 addition & 0 deletions src/rpc/rpcutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ Value mc_ExtractDetailsJSONObject(const unsigned char *script,uint32_t total);
void AppendOffChainFormatData(uint32_t data_format,uint32_t out_options,mc_Script *lpDetailsScript,vector<unsigned char>& vValue,vector<uint256>* vChunkHashes,int *errorCode,string *strError);
int mc_BinaryCacheFile(string id,int mode);
void mc_RemoveBinaryCacheFile(string id);
bool AvailableFromStatus(uint32_t status);
string OffChainError(uint32_t status,int *errorCode);
bool RawDataParseRestrictParameter(const Value& param,uint32_t *restrict,uint32_t *permissions,string *strError);

Expand Down
11 changes: 11 additions & 0 deletions src/rpc/rpcwalletutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,17 @@ Object StreamItemEntry(const CWalletTx& wtx,int first_output,const unsigned char
entry.push_back(Pair("key", keys[0]));
}
entry.push_back(Pair("data", format_item_value));
if( ( retrieve_status & MC_OST_CONTROL_NO_DATA ) == 0)
{
if(retrieve_status & MC_OST_ERROR_MASK)
{
string error_str;
int errorCode;
error_str=OffChainError(retrieve_status,&errorCode);
entry.push_back(Pair("error", error_str));
}
entry.push_back(Pair("available", AvailableFromStatus(retrieve_status)));
}
entry.push_back(Pair("offchain", (retrieve_status & MC_OST_STORAGE_MASK) == MC_OST_OFF_CHAIN));

if(verbose)
Expand Down

0 comments on commit 12cc667

Please sign in to comment.