mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
XChainBridge: Introduce sidechain support (XLS-38): (#4292)
A bridge connects two blockchains: a locking chain and an issuing chain (also called a mainchain and a sidechain). Both are independent ledgers, with their own validators and potentially their own custom transactions. Importantly, there is a way to move assets from the locking chain to the issuing chain and a way to return those assets from the issuing chain back to the locking chain: the bridge. This key operation is called a cross-chain transfer. A cross-chain transfer is not a single transaction. It happens on two chains, requires multiple transactions, and involves an additional server type called a "witness". A bridge does not exchange assets between two ledgers. Instead, it locks assets on one ledger (the "locking chain") and represents those assets with wrapped assets on another chain (the "issuing chain"). A good model to keep in mind is a box with an infinite supply of wrapped assets. Putting an asset from the locking chain into the box will release a wrapped asset onto the issuing chain. Putting a wrapped asset from the issuing chain back into the box will release one of the existing locking chain assets back onto the locking chain. There is no other way to get assets into or out of the box. Note that there is no way for the box to "run out of" wrapped assets - it has an infinite supply. Co-authored-by: Gregory Popovitch <greg7mdp@gmail.com>
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include <test/jtx.h>
|
||||
#include <test/jtx/WSClient.h>
|
||||
#include <test/jtx/envconfig.h>
|
||||
#include <tuple>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
@@ -743,7 +744,7 @@ public:
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
using namespace jtx;
|
||||
using IdxHashVec = std::vector<std::pair<int, std::string>>;
|
||||
using IdxHashVec = std::vector<std::tuple<int, std::string, bool, int>>;
|
||||
|
||||
Account alice("alice");
|
||||
Account bob("bob");
|
||||
@@ -781,11 +782,14 @@ public:
|
||||
idx = r[jss::account_history_tx_index].asInt();
|
||||
if (r.isMember(jss::account_history_tx_first))
|
||||
first_flag = true;
|
||||
bool boundary = r.isMember(jss::account_history_boundary);
|
||||
int ledger_idx = r[jss::ledger_index].asInt();
|
||||
if (r.isMember(jss::transaction) &&
|
||||
r[jss::transaction].isMember(jss::hash))
|
||||
{
|
||||
auto t{r[jss::transaction]};
|
||||
v.emplace_back(
|
||||
idx, r[jss::transaction][jss::hash].asString());
|
||||
idx, t[jss::hash].asString(), boundary, ledger_idx);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -838,13 +842,13 @@ public:
|
||||
hash_map<std::string, int> txHistoryMap;
|
||||
for (auto const& tx : txHistoryVec)
|
||||
{
|
||||
txHistoryMap.emplace(tx.second, tx.first);
|
||||
txHistoryMap.emplace(std::get<1>(tx), std::get<0>(tx));
|
||||
}
|
||||
|
||||
auto getHistoryIndex = [&](std::size_t i) -> std::optional<int> {
|
||||
if (i >= accountVec.size())
|
||||
return {};
|
||||
auto it = txHistoryMap.find(accountVec[i].second);
|
||||
auto it = txHistoryMap.find(std::get<1>(accountVec[i]));
|
||||
if (it == txHistoryMap.end())
|
||||
return {};
|
||||
return it->second;
|
||||
@@ -862,6 +866,48 @@ public:
|
||||
return true;
|
||||
};
|
||||
|
||||
// example of vector created from the return of `subscribe` rpc
|
||||
// with jss::accounts
|
||||
// boundary == true on last tx of ledger
|
||||
// ------------------------------------------------------------
|
||||
// (0, "E5B8B...", false, 4
|
||||
// (0, "39E1C...", false, 4
|
||||
// (0, "14EF1...", false, 4
|
||||
// (0, "386E6...", false, 4
|
||||
// (0, "00F3B...", true, 4
|
||||
// (0, "1DCDC...", false, 5
|
||||
// (0, "BD02A...", false, 5
|
||||
// (0, "D3E16...", false, 5
|
||||
// (0, "CB593...", false, 5
|
||||
// (0, "8F28B...", true, 5
|
||||
//
|
||||
// example of vector created from the return of `subscribe` rpc
|
||||
// with jss::account_history_tx_stream.
|
||||
// boundary == true on first tx of ledger
|
||||
// ------------------------------------------------------------
|
||||
// (-1, "8F28B...", false, 5
|
||||
// (-2, "CB593...", false, 5
|
||||
// (-3, "D3E16...", false, 5
|
||||
// (-4, "BD02A...", false, 5
|
||||
// (-5, "1DCDC...", true, 5
|
||||
// (-6, "00F3B...", false, 4
|
||||
// (-7, "386E6...", false, 4
|
||||
// (-8, "14EF1...", false, 4
|
||||
// (-9, "39E1C...", false, 4
|
||||
// (-10, "E5B8B...", true, 4
|
||||
|
||||
auto checkBoundary = [](IdxHashVec const& vec, bool /* forward */) {
|
||||
size_t num_tx = vec.size();
|
||||
for (size_t i = 0; i < num_tx; ++i)
|
||||
{
|
||||
auto [idx, hash, boundary, ledger] = vec[i];
|
||||
if ((i + 1 == num_tx || ledger != std::get<3>(vec[i + 1])) !=
|
||||
boundary)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
{
|
||||
@@ -880,6 +926,7 @@ public:
|
||||
auto jv = wscTxHistory->invoke("subscribe", request);
|
||||
if (!BEAST_EXPECT(goodSubRPC(jv)))
|
||||
return;
|
||||
|
||||
jv = wscTxHistory->invoke("subscribe", request);
|
||||
BEAST_EXPECT(!goodSubRPC(jv));
|
||||
|
||||
@@ -911,7 +958,6 @@ public:
|
||||
r = getTxHash(*wscTxHistory, vec, 1);
|
||||
BEAST_EXPECT(!r.first);
|
||||
}
|
||||
|
||||
{
|
||||
/*
|
||||
* subscribe genesis account tx history without txns
|
||||
@@ -950,8 +996,8 @@ public:
|
||||
if (!BEAST_EXPECT(r.first && r.second))
|
||||
return;
|
||||
BEAST_EXPECT(
|
||||
bobFullHistoryVec.back().second ==
|
||||
genesisFullHistoryVec.back().second);
|
||||
std::get<1>(bobFullHistoryVec.back()) ==
|
||||
std::get<1>(genesisFullHistoryVec.back()));
|
||||
|
||||
/*
|
||||
* unsubscribe to prepare next test
|
||||
@@ -987,8 +1033,8 @@ public:
|
||||
jv = wscTxHistory->invoke("unsubscribe", request);
|
||||
|
||||
BEAST_EXPECT(
|
||||
bobFullHistoryVec.back().second ==
|
||||
genesisFullHistoryVec.back().second);
|
||||
std::get<1>(bobFullHistoryVec.back()) ==
|
||||
std::get<1>(genesisFullHistoryVec.back()));
|
||||
}
|
||||
|
||||
{
|
||||
@@ -1030,11 +1076,17 @@ public:
|
||||
if (!BEAST_EXPECT(hashCompare(accountVec, txHistoryVec, true)))
|
||||
return;
|
||||
|
||||
// check boundary tags
|
||||
// only account_history_tx_stream has ledger boundary information.
|
||||
if (!BEAST_EXPECT(checkBoundary(txHistoryVec, false)))
|
||||
return;
|
||||
|
||||
{
|
||||
// take out all history txns from stream to prepare next test
|
||||
IdxHashVec initFundTxns;
|
||||
if (!BEAST_EXPECT(
|
||||
getTxHash(*wscTxHistory, initFundTxns, 10).second))
|
||||
getTxHash(*wscTxHistory, initFundTxns, 10).second) ||
|
||||
!BEAST_EXPECT(checkBoundary(initFundTxns, false)))
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1046,6 +1098,12 @@ public:
|
||||
return;
|
||||
if (!BEAST_EXPECT(hashCompare(accountVec, txHistoryVec, true)))
|
||||
return;
|
||||
|
||||
// check boundary tags
|
||||
// only account_history_tx_stream has ledger boundary information.
|
||||
if (!BEAST_EXPECT(checkBoundary(txHistoryVec, false)))
|
||||
return;
|
||||
|
||||
wscTxHistory->invoke("unsubscribe", request);
|
||||
wscAccount->invoke("unsubscribe", stream);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user