Skip to content
This repository was archived by the owner on Aug 27, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 6 additions & 63 deletions src/libServer/EthRpcMethods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,6 @@ std::string EthRpcMethods::CreateTransactionEth(

const unsigned int shard = Transaction::GetShardIndex(fromAddr, num_shards);
unsigned int mapIndex = shard;
bool priority = false;
switch (Transaction::GetTransactionType(tx)) {
case Transaction::ContractType::NON_CONTRACT:
if (ARCHIVAL_LOOKUP) {
Expand All @@ -473,15 +472,15 @@ std::string EthRpcMethods::CreateTransactionEth(
// A simple transfer to an account that is a contract
// is processed like a CONTRACT_CALL.
auto check =
CheckContractTxnShards(priority, shard, tx, num_shards,
CheckContractTxnShards(tx, num_shards,
toAccountExist, toAccountIsContract);
mapIndex = check.second;
}
break;
case Transaction::ContractType::CONTRACT_CREATION:
case Transaction::ContractType::CONTRACT_CALL: {
auto check =
CheckContractTxnShards(priority, shard, tx, num_shards,
CheckContractTxnShards(tx, num_shards,
toAccountExist, toAccountIsContract);
mapIndex = check.second;
} break;
Expand Down Expand Up @@ -517,66 +516,10 @@ std::string EthRpcMethods::CreateTransactionEth(
}

std::pair<std::string, unsigned int> EthRpcMethods::CheckContractTxnShards(
bool priority, unsigned int shard, const Transaction &tx,
unsigned int num_shards, bool toAccountExist, bool toAccountIsContract) {
INC_CALLS(GetInvocationsCounter());

unsigned int mapIndex = shard;
std::string resultStr;

if (!ENABLE_SC) {
throw JsonRpcException(ServerBase::RPC_MISC_ERROR,
"Smart contract is disabled");
}

if (!toAccountExist) {
throw JsonRpcException(ServerBase::RPC_INVALID_ADDRESS_OR_KEY,
"Target account does not exist");
} else if (Transaction::GetTransactionType(tx) ==
Transaction::CONTRACT_CALL &&
!toAccountIsContract) {
throw JsonRpcException(ServerBase::RPC_INVALID_ADDRESS_OR_KEY,
"Non - contract address called");
}

Address affectedAddress =
(Transaction::GetTransactionType(tx) == Transaction::CONTRACT_CREATION)
? Account::GetAddressForContract(tx.GetSenderAddr(), tx.GetNonce(),
tx.GetVersionIdentifier())
: tx.GetToAddr();

unsigned int to_shard =
Transaction::GetShardIndex(affectedAddress, num_shards);
// Use m_sendSCCallsToDS as initial setting
bool sendToDs = priority || m_sharedMediator.m_lookup->m_sendSCCallsToDS;
if ((to_shard == shard) && !sendToDs) {
if (tx.GetGasLimitZil() > SHARD_MICROBLOCK_GAS_LIMIT) {
throw JsonRpcException(ServerBase::RPC_INVALID_PARAMETER,
"txn gas limit exceeding shard maximum limit");
}
if (ARCHIVAL_LOOKUP) {
mapIndex = SEND_TYPE::ARCHIVAL_SEND_SHARD;
}
resultStr =
"Contract Creation/Call Txn, Shards Match of the sender "
"and receiver";
} else {
if (tx.GetGasLimitZil() > DS_MICROBLOCK_GAS_LIMIT) {
throw JsonRpcException(
ServerBase::RPC_INVALID_PARAMETER,
(boost::format(
"txn gas limit exceeding ds maximum limit! Tx: %i DS: %i") %
tx.GetGasLimitZil() % DS_MICROBLOCK_GAS_LIMIT)
.str());
}
if (ARCHIVAL_LOOKUP) {
mapIndex = SEND_TYPE::ARCHIVAL_SEND_DS;
} else {
mapIndex = num_shards;
}
resultStr = "Contract Creation/Call Txn, Sent To Ds";
}
return make_pair(resultStr, mapIndex);
const Transaction &tx, unsigned int num_shards, bool toAccountExist,
bool toAccountIsContract) {
return m_lookupServer->CheckContractTxnShards(tx, num_shards, toAccountExist,
toAccountIsContract);
}

Json::Value EthRpcMethods::GetBalanceAndNonce(const string &address) {
Expand Down
4 changes: 2 additions & 2 deletions src/libServer/EthRpcMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class EthRpcMethods {
"Calls to ethereum API", "Calls"};

std::pair<std::string, unsigned int> CheckContractTxnShards(
bool priority, unsigned int shard, const Transaction& tx,
unsigned int num_shards, bool toAccountExist, bool toAccountIsContract);
const Transaction& tx, unsigned int num_shards, bool toAccountExist,
bool toAccountIsContract);

CreateTransactionTargetFunc m_createTransactionTarget =
[this](const Transaction& tx, uint32_t shardId) -> bool {
Expand Down
65 changes: 10 additions & 55 deletions src/libServer/LookupServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,10 +610,6 @@ Json::Value LookupServer::CreateTransaction(

const unsigned int shard = Transaction::GetShardIndex(fromAddr, num_shards);
unsigned int mapIndex = shard;
bool priority = false;
if (_json.isMember("priority")) {
priority = _json["priority"].asBool();
}
switch (Transaction::GetTransactionType(tx)) {
case Transaction::ContractType::NON_CONTRACT:
if (ARCHIVAL_LOOKUP) {
Expand All @@ -633,9 +629,8 @@ Json::Value LookupServer::CreateTransaction(
// We use the same logic for CONTRACT_CREATION and CONTRACT_CALL.
// TODO(valeryz): once we stop using Zilliqa APIs for EVM, revert
// to the old behavior where CONTRACT_CREATION can be sharded.
auto check =
CheckContractTxnShards(priority, shard, tx, num_shards,
toAccountExist, toAccountIsContract);
auto check = CheckContractTxnShards(tx, num_shards, toAccountExist,
toAccountIsContract);
ret["Info"] = check.first;
ret["ContractAddress"] =
Account::GetAddressForContract(fromAddr, tx.GetNonce() - 1,
Expand All @@ -644,9 +639,8 @@ Json::Value LookupServer::CreateTransaction(
mapIndex = check.second;
} break;
case Transaction::ContractType::CONTRACT_CALL: {
auto check =
CheckContractTxnShards(priority, shard, tx, num_shards,
toAccountExist, toAccountIsContract);
auto check = CheckContractTxnShards(tx, num_shards, toAccountExist,
toAccountIsContract);
ret["Info"] = check.first;
mapIndex = check.second;
} break;
Expand Down Expand Up @@ -2359,15 +2353,12 @@ Json::Value LookupServer::GetStateProof(const string& address,
}

std::pair<std::string, unsigned int> LookupServer::CheckContractTxnShards(
bool priority, unsigned int shard, const Transaction& tx,
const Transaction& tx,
unsigned int num_shards, bool toAccountExist, bool toAccountIsContract) {
TRACE(zil::trace::FilterClass::DEMO);

INC_CALLS(GetCallsCounter());

unsigned int mapIndex = shard;
std::string resultStr;

if (!ENABLE_SC) {
throw JsonRpcException(ServerBase::RPC_MISC_ERROR,
"Smart contract is disabled");
Expand All @@ -2384,47 +2375,11 @@ std::pair<std::string, unsigned int> LookupServer::CheckContractTxnShards(
"Non - contract address called");
}

Transaction::ContractType scType = Transaction::GetTransactionType(tx);

// Use m_sendSCCallsToDS as initial setting
bool sendToDs = priority || m_sharedMediator.m_lookup->m_sendSCCallsToDS;
if (!tx.IsEth() && scType == Transaction::CONTRACT_CREATION) {
// Scilla smart CONTRACT_CREATION call should be executed in shard rather
// than DS.
mapIndex = SEND_TYPE::ARCHIVAL_SEND_SHARD;
resultStr = "Contract Creation txn, sent to shard";
unsigned int mapIndex;
if (ARCHIVAL_LOOKUP) {
mapIndex = SEND_TYPE::ARCHIVAL_SEND_DS;
} else {
// CONTRACT_CALL - scilla and EVM , CONTRACT_CREATION - EVM
Address affectedAddress = tx.GetToAddr();
unsigned int to_shard =
Transaction::GetShardIndex(affectedAddress, num_shards);
if ((to_shard == shard) && !sendToDs) {
if (tx.GetGasLimitZil() > SHARD_MICROBLOCK_GAS_LIMIT) {
throw JsonRpcException(ServerBase::RPC_INVALID_PARAMETER,
"txn gas limit exceeding shard maximum limit");
}
if (ARCHIVAL_LOOKUP) {
mapIndex = SEND_TYPE::ARCHIVAL_SEND_SHARD;
}
resultStr =
"Contract Creation/Call Txn, Shards Match of the sender "
"and receiver";
} else {
if (tx.GetGasLimitZil() > DS_MICROBLOCK_GAS_LIMIT) {
throw JsonRpcException(
ServerBase::RPC_INVALID_PARAMETER,
(boost::format(
"txn gas limit exceeding ds maximum limit! Tx: %i DS: %i") %
tx.GetGasLimitZil() % DS_MICROBLOCK_GAS_LIMIT)
.str());
}
if (ARCHIVAL_LOOKUP) {
mapIndex = SEND_TYPE::ARCHIVAL_SEND_DS;
} else {
mapIndex = num_shards;
}
resultStr = "Contract Creation/Call Txn, Sent To Ds";
}
mapIndex = num_shards;
}
return make_pair(resultStr, mapIndex);
return make_pair("Contract Creation/Call Txn, Sent To Ds", mapIndex);
}
7 changes: 4 additions & 3 deletions src/libServer/LookupServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ class LookupServer : public Server,
Json::Value GetTransactionsForTxBlock(const std::string& txBlockNum,
const std::string& pageNumber);

std::pair<std::string, unsigned int> CheckContractTxnShards(
bool priority, unsigned int shard, const Transaction& tx,
unsigned int num_shards, bool toAccountExist, bool toAccountIsContract);
mp::cpp_dec_float_50 CalculateTotalSupply();

public:
Expand Down Expand Up @@ -362,6 +359,10 @@ class LookupServer : public Server,
bool StartCollectorThread();
std::string GetNodeState();

std::pair<std::string, unsigned int> CheckContractTxnShards(
const Transaction& tx, unsigned int num_shards, bool toAccountExist,
bool toAccountIsContract);

static void AddToRecentTransactions(const dev::h256& txhash);

// gets the number of transaction starting from block blockNum to most recent
Expand Down