Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

evm: Deploy DST20 for loan tokens #2258

Merged
merged 32 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
234dd33
Fix DST20 test
shohamc1 Jul 31, 2023
69d8b7a
Deploy DST20 for loan tokens
shohamc1 Jul 31, 2023
39209b1
Merge remote-tracking branch 'origin/master' into evm/dst20-loan-tokens
shohamc1 Jul 31, 2023
9f11c1d
Fix lint
shohamc1 Jul 31, 2023
c384e57
Rename failible dst20 FFI methods
Jouzo Jul 31, 2023
7ac6618
Reduce log level of fee_history
Jouzo Jul 31, 2023
a6f8d67
Fix clippy default_constructed_unit_structs
Jouzo Aug 1, 2023
39789b2
Adds FFI evm_try_dst20_is_deployed method
Jouzo Aug 1, 2023
0f5fae1
Fix clippy useless conversion
Jouzo Aug 1, 2023
bf8a33d
Fix clippy used-underscore-binding
Jouzo Aug 1, 2023
e3aac7a
Create DST20 loan token via attributes
Bushstar Aug 1, 2023
5c4dbb0
Separate LoanCollateralEnabled logic
Bushstar Aug 1, 2023
739e8b1
Merge branch 'master' into evm/dst20-loan-tokens
shohamc1 Aug 2, 2023
9e96865
Set correct queue ID
Bushstar Aug 2, 2023
379f708
Use full path
Bushstar Aug 2, 2023
a2fb841
Merge branch 'master' into evm/dst20-loan-tokens
Bushstar Aug 2, 2023
3477d10
Rename to is_dst20_deployed_or_queued
Jouzo Aug 4, 2023
18774ad
Merge branch master into evm/dst20-loan-tokens
Jouzo Aug 4, 2023
0cc8d94
Merge branch 'master' into evm/dst20-loan-tokens
Jouzo Aug 4, 2023
0072de6
Merge branch master into evm/dst20-loan-tokens
Jouzo Aug 7, 2023
db68693
Merge branch 'master' into evm/dst20-loan-tokens
prasannavl Aug 7, 2023
565c79f
Migrate DST20 tokens on EVM genesis block
Jouzo Aug 8, 2023
0c3f997
Remove unused ProcessDST20Migration parameters
Jouzo Aug 8, 2023
c16a404
Merge branch master into evm/dst20-loan-tokens
Jouzo Aug 8, 2023
71f7924
Fix lint
Jouzo Aug 8, 2023
a53f088
Add target_block to TransactionQueue
Jouzo Aug 8, 2023
7678d86
Use target_block and append to queue before processing
Jouzo Aug 8, 2023
2a9694b
Merge branch 'master' into evm/dst20-loan-tokens
Jouzo Aug 8, 2023
fda389e
Verify loan token is DAT
Bushstar Aug 8, 2023
e30f1fa
Remove second ForEachLoanToken loop
Jouzo Aug 9, 2023
09a12a9
Merge branch 'master' into evm/dst20-loan-tokens
prasannavl Aug 10, 2023
f10de16
Resolve lints
prasannavl Aug 10, 2023
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
10 changes: 4 additions & 6 deletions lib/ain-evm/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub struct FinalizedBlockInfo {
pub failed_transactions: Vec<String>,
pub total_burnt_fees: U256,
pub total_priority_fees: U256,
pub block_number: U256,
}

pub struct DeployContractInfo {
Expand Down Expand Up @@ -343,6 +344,7 @@ impl EVMServices {
failed_transactions,
total_burnt_fees,
total_priority_fees,
block_number: current_block_number,
})
}

Expand Down Expand Up @@ -524,7 +526,7 @@ impl EVMServices {
})
}

pub fn is_dst20_deployed_or_queued(
pub unsafe fn is_dst20_deployed_or_queued(
&self,
queue_id: u64,
name: &str,
Expand All @@ -549,11 +551,7 @@ impl EVMServices {
address,
}));

let is_queued = self
.core
.tx_queues
.get_queue(queue_id)?
.is_queued(deploy_tx);
let is_queued = self.core.tx_queues.get(queue_id)?.is_queued(deploy_tx);

Ok(is_queued)
}
Expand Down
16 changes: 10 additions & 6 deletions lib/ain-rs-exports/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,13 +424,15 @@ pub fn evm_unsafe_try_construct_block_in_q(
failed_transactions,
total_burnt_fees,
total_priority_fees,
block_number,
}) => {
cross_boundary_success(result);
ffi::FinalizeBlockCompletion {
block_hash,
failed_transactions,
total_burnt_fees: WeiAmount(total_burnt_fees).to_satoshi().as_u64(),
total_priority_fees: WeiAmount(total_priority_fees).to_satoshi().as_u64(),
block_number: block_number.as_u64(),
}
}
Err(e) => cross_boundary_error_return(result, e.to_string()),
Expand Down Expand Up @@ -508,12 +510,14 @@ pub fn evm_try_is_dst20_deployed_or_queued(
symbol: &str,
token_id: &str,
) -> bool {
match SERVICES
.evm
.is_dst20_deployed_or_queued(queue_id, name, symbol, token_id)
{
Ok(is_deployed) => cross_boundary_success_return(result, is_deployed),
Err(e) => cross_boundary_error_return(result, e.to_string()),
unsafe {
match SERVICES
.evm
.is_dst20_deployed_or_queued(queue_id, name, symbol, token_id)
{
Ok(is_deployed) => cross_boundary_success_return(result, is_deployed),
Err(e) => cross_boundary_error_return(result, e.to_string()),
}
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/ain-rs-exports/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub mod ffi {
pub failed_transactions: Vec<String>,
pub total_burnt_fees: u64,
pub total_priority_fees: u64,
pub block_number: u64,
}

#[derive(Default)]
Expand Down
36 changes: 32 additions & 4 deletions src/masternodes/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2386,7 +2386,7 @@ static Res ValidateCoinbaseXVMOutput(const CScript &scriptPubKey, const Finalize

auto res = XVM::TryFrom(scriptPubKey);
if (!res.ok) return res;

auto obj = *res;

if (obj.evm.blockHash != coinbaseBlockHash) {
Expand All @@ -2404,8 +2404,8 @@ static Res ValidateCoinbaseXVMOutput(const CScript &scriptPubKey, const Finalize
return Res::Ok();
}

static Res ProcessEVMQueue(const CBlock &block, const CBlockIndex *pindex, CCustomCSView &cache, const CChainParams& chainparams, const uint64_t evmQueueId, std::array<uint8_t, 20>& beneficiary, const bool evmEnabledOnBlockHead) {
if (!IsEVMEnabled(pindex->nHeight, cache, chainparams.GetConsensus())) return Res::Ok();
static ResVal<uint64_t> ProcessEVMQueue(const CBlock &block, const CBlockIndex *pindex, CCustomCSView &cache, const CChainParams& chainparams, const uint64_t evmQueueId, std::array<uint8_t, 20>& beneficiary, const bool evmEnabledOnBlockHead) {
if (!IsEVMEnabled(pindex->nHeight, cache, chainparams.GetConsensus())) return {std::numeric_limits<uint64_t>::max(), Res::Ok()};

CKeyID minter;
assert(block.ExtractMinterKey(minter));
Expand Down Expand Up @@ -2484,9 +2484,31 @@ static Res ProcessEVMQueue(const CBlock &block, const CBlockIndex *pindex, CCust
res = cache.AddBalance(minerAddress, {DCT_ID{}, static_cast<CAmount>(blockResult.total_priority_fees)});
if (!res) return res;

return Res::Ok();
return {blockResult.block_number, Res::Ok()};
}


static Res ProcessDST20Migration(const CBlock &block, const CBlockIndex *pindex, CCustomCSView &cache, const CChainParams& chainparams, const uint64_t evmQueueId, std::array<uint8_t, 20>& beneficiary, const bool evmEnabledOnBlockHead) {
Jouzo marked this conversation as resolved.
Show resolved Hide resolved
if (!IsEVMEnabled(pindex->nHeight, cache, chainparams.GetConsensus())) return Res::Ok();
auto time = GetTimeMillis();
LogPrintf("DST20 migration ...\n");

CrossBoundaryResult result;
cache.ForEachLoanToken([&](DCT_ID const & key, CLoanView::CLoanSetLoanTokenImpl loanToken) {
Jouzo marked this conversation as resolved.
Show resolved Hide resolved
if (evm_try_is_dst20_deployed_or_queued(result, evmQueueId, loanToken.name, loanToken.symbol, key.ToString())) {
return result.ok;
}

evm_try_create_dst20(result, evmQueueId, loanToken.creationTx.GetByteArray(),
loanToken.name, loanToken.symbol, key.ToString());
return result.ok;
});
LogPrint(BCLog::BENCH, " - DST20 migration took: %dms\n", GetTimeMillis() - time);
return result.ok ? Res::Ok() : Res::Err("Error migrating DST20 token: %s", result.reason.c_str());
}



static void FlushCacheCreateUndo(const CBlockIndex *pindex, CCustomCSView &mnview, CCustomCSView &cache, const uint256 hash) {
// construct undo
auto& flushable = cache.GetStorage();
Expand All @@ -2506,6 +2528,12 @@ Res ProcessFallibleEvent(const CBlock &block, const CBlockIndex *pindex, CCustom
auto res = ProcessEVMQueue(block, pindex, cache, chainparams, evmQueueId, beneficiary, evmEnabledOnBlockHead);
if (!res) return res;

auto isEVMGenesisBlock = *res.val == 0;
if (isEVMGenesisBlock) {
auto res = ProcessDST20Migration(block, pindex, cache, chainparams, evmQueueId, beneficiary, evmEnabledOnBlockHead);
if (!res) return res;
}

// Construct undo
FlushCacheCreateUndo(pindex, mnview, cache, uint256S(std::string(64, '1')));

Expand Down
2 changes: 1 addition & 1 deletion src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2410,7 +2410,7 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
if (pindex->nHeight == chainparams.GetConsensus().FortCanningHillHeight) {
auto time = GetTimeMillis();
LogPrintf("Interest rate migration ...\n");
mnview.MigrateInterestRateToV2(mnview,(uint32_t)pindex->nHeight);
mnview.MigrateInterestRateToV2(mnview, static_cast<uint32_t>(pindex->nHeight));
LogPrint(BCLog::BENCH, " - Interest rate migration took: %dms\n", GetTimeMillis() - time);
}

Expand Down