From d6860b15d15314e0040e4e8feb938a609e87e6b8 Mon Sep 17 00:00:00 2001 From: Mark Jabbour Date: Thu, 21 Jul 2022 22:15:22 +0000 Subject: [PATCH 1/3] make pythd robust --- pc/request.cpp | 6 +++--- program/c/src/oracle/oracle.h | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pc/request.cpp b/pc/request.cpp index 6f70b2c75..b95a175c0 100644 --- a/pc/request.cpp +++ b/pc/request.cpp @@ -354,7 +354,7 @@ void product::update( T *res ) return; } pc_prod_t *prod; - size_t plen = std::max( sizeof(pc_price_t), (size_t)PC_PROD_ACC_SIZE ); + size_t plen = std::max( PRICE_ACCOUNT_SIZE, (size_t)PC_PROD_ACC_SIZE ); if ( sizeof( pc_prod_t ) > res->get_data_ref( prod, plen ) || prod->magic_ != PC_MAGIC || !init_from_account( prod ) ) { @@ -464,7 +464,7 @@ price::price( const pub_key& acc, product *prod ) preq_->set_account( &apub_ ); areq_->set_sub( this ); preq_->set_sub( this ); - size_t tlen = ZSTD_compressBound( sizeof(pc_price_t) ); + size_t tlen = ZSTD_compressBound( PRICE_ACCOUNT_SIZE ); pptr_ = (pc_price_t*)new char[tlen]; __builtin_memset( pptr_, 0, tlen ); } @@ -952,7 +952,7 @@ void price::update( T *res ) } // get account data - size_t tlen = ZSTD_compressBound( sizeof(pc_price_t) ); + size_t tlen = ZSTD_compressBound( PRICE_ACCOUNT_SIZE ); res->get_data_val( pptr_, tlen ); if ( PC_UNLIKELY( pptr_->magic_ != PC_MAGIC ) ) { on_error_sub( "bad price account header", this ); diff --git a/program/c/src/oracle/oracle.h b/program/c/src/oracle/oracle.h index 6ca196855..ab574952c 100644 --- a/program/c/src/oracle/oracle.h +++ b/program/c/src/oracle/oracle.h @@ -190,6 +190,8 @@ typedef struct pc_price static_assert( sizeof( pc_price_t ) == 3312, "" ); +const uint64_t PRICE_ACCOUNT_SIZE = TIME_MACHINE_STRUCT_SIZE + sizeof( pc_price_t ); + // command enumeration typedef enum { From 891d42e9bff46321d03b9cce266d72f1de33234a Mon Sep 17 00:00:00 2001 From: Mark Jabbour Date: Thu, 21 Jul 2022 22:23:17 +0000 Subject: [PATCH 2/3] made the oracle accept new size --- program/c/src/oracle/oracle.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/program/c/src/oracle/oracle.c b/program/c/src/oracle/oracle.c index 17cbfc653..b7ab6e55e 100644 --- a/program/c/src/oracle/oracle.c +++ b/program/c/src/oracle/oracle.c @@ -5,6 +5,7 @@ #include "oracle.h" #include "upd_aggregate.h" + // Returns the minimum number of lamports required to make an account // with dlen bytes of data rent exempt. These values were calculated // using the getMinimumBalanceForRentExemption RPC call, and are @@ -19,6 +20,8 @@ static uint64_t rent_exempt_amount( uint64_t dlen ) return 4454400; case sizeof( pc_price_t ): return 23942400; + case PRICE_ACCOUNT_SIZE: + return 36915840; default: return UINT64_MAX; } From 0984ef573d9ad2ffd9fc24d8990482aa61a37b24 Mon Sep 17 00:00:00 2001 From: Mark Jabbour Date: Fri, 22 Jul 2022 00:23:31 +0000 Subject: [PATCH 3/3] left space for extra publishers --- program/c/src/oracle/oracle.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/program/c/src/oracle/oracle.h b/program/c/src/oracle/oracle.h index ab574952c..ea4fa8bba 100644 --- a/program/c/src/oracle/oracle.h +++ b/program/c/src/oracle/oracle.h @@ -17,6 +17,9 @@ const uint64_t SUCCESSFULLY_UPDATED_AGGREGATE = 1000ULL; // Rust portion of the codebase. const uint64_t TIME_MACHINE_STRUCT_SIZE = 1864ULL; +const uint64_t EXTRA_PUBLISHER_SPACE = 1000ULL; + + // magic number at head of account #define PC_MAGIC 0xa1b2c3d4 @@ -190,7 +193,7 @@ typedef struct pc_price static_assert( sizeof( pc_price_t ) == 3312, "" ); -const uint64_t PRICE_ACCOUNT_SIZE = TIME_MACHINE_STRUCT_SIZE + sizeof( pc_price_t ); +const uint64_t PRICE_ACCOUNT_SIZE = TIME_MACHINE_STRUCT_SIZE + EXTRA_PUBLISHER_SPACE + sizeof( pc_price_t ); // command enumeration typedef enum {