rippled
Loading...
Searching...
No Matches
XChainBridge.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2022 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_TX_XCHAINBRIDGE_H_INCLUDED
21#define RIPPLE_TX_XCHAINBRIDGE_H_INCLUDED
22
23#include <xrpld/app/tx/detail/Transactor.h>
24
25#include <xrpl/protocol/XChainAttestations.h>
26
27namespace ripple {
28
29constexpr size_t xbridgeMaxAccountCreateClaims = 128;
30
31// Attach a new bridge to a door account. Once this is done, the cross-chain
32// transfer transactions may be used to transfer funds from this account.
34{
35public:
37
39 {
40 }
41
42 static NotTEC
43 preflight(PreflightContext const& ctx);
44
45 static TER
46 preclaim(PreclaimContext const& ctx);
47
48 TER
49 doApply() override;
50};
51
53{
54public:
56
57 explicit BridgeModify(ApplyContext& ctx) : Transactor(ctx)
58 {
59 }
60
61 static std::uint32_t
63
64 static NotTEC
65 preflight(PreflightContext const& ctx);
66
67 static TER
68 preclaim(PreclaimContext const& ctx);
69
70 TER
71 doApply() override;
72};
73
75
76//------------------------------------------------------------------------------
77
78// Claim funds from a `XChainCommit` transaction. This is normally not needed,
79// but may be used to handle transaction failures or if the destination account
80// was not specified in the `XChainCommit` transaction. It may only be used
81// after a quorum of signatures have been sent from the witness servers.
82//
83// If the transaction succeeds in moving funds, the referenced `XChainClaimID`
84// ledger object will be destroyed. This prevents transaction replay. If the
85// transaction fails, the `XChainClaimID` will not be destroyed and the
86// transaction may be re-run with different parameters.
87class XChainClaim : public Transactor
88{
89public:
90 // Blocker since we cannot accurately calculate the consequences
92
93 explicit XChainClaim(ApplyContext& ctx) : Transactor(ctx)
94 {
95 }
96
97 static NotTEC
98 preflight(PreflightContext const& ctx);
99
100 static TER
101 preclaim(PreclaimContext const& ctx);
102
103 TER
104 doApply() override;
105};
106
107//------------------------------------------------------------------------------
108
109// Put assets into trust on the locking-chain so they may be wrapped on the
110// issuing-chain, or return wrapped assets on the issuing-chain so they can be
111// unlocked on the locking-chain. The second step in a cross-chain transfer.
113{
114public:
116
117 static TxConsequences
119
121 {
122 }
123
124 static NotTEC
125 preflight(PreflightContext const& ctx);
126
127 static TER
128 preclaim(PreclaimContext const& ctx);
129
130 TER
131 doApply() override;
132};
133
134//------------------------------------------------------------------------------
135
136// Create a new claim id owned by the account. This is the first step in a
137// cross-chain transfer. The claim id must be created on the destination chain
138// before the `XChainCommit` transaction (which must reference this number) can
139// be sent on the source chain. The account that will send the `XChainCommit` on
140// the source chain must be specified in this transaction (see note on the
141// `SourceAccount` field in the `XChainClaimID` ledger object for
142// justification). The actual sequence number must be retrieved from a validated
143// ledger.
145{
146public:
148
150 {
151 }
152
153 static NotTEC
154 preflight(PreflightContext const& ctx);
155
156 static TER
157 preclaim(PreclaimContext const& ctx);
158
159 TER
160 doApply() override;
161};
162
163//------------------------------------------------------------------------------
164
165// Provide attestations from a witness server attesting to events on
166// the other chain. The signatures must be from one of the keys on the door's
167// signer's list at the time the signature was provided. However, if the
168// signature list changes between the time the signature was submitted and the
169// quorum is reached, the new signature set is used and some of the currently
170// collected signatures may be removed. Also note the reward is only sent to
171// accounts that have keys on the current list.
173{
174public:
175 // Blocker since we cannot accurately calculate the consequences
177
179 {
180 }
181
182 static NotTEC
183 preflight(PreflightContext const& ctx);
184
185 static TER
186 preclaim(PreclaimContext const& ctx);
187
188 TER
189 doApply() override;
190};
191
193{
194public:
195 // Blocker since we cannot accurately calculate the consequences
197
199 : Transactor(ctx)
200 {
201 }
202
203 static NotTEC
204 preflight(PreflightContext const& ctx);
205
206 static TER
207 preclaim(PreclaimContext const& ctx);
208
209 TER
210 doApply() override;
211};
212
213//------------------------------------------------------------------------------
214
215// This is a special transaction used for creating accounts through a
216// cross-chain transfer. A normal cross-chain transfer requires a "chain claim
217// id" (which requires an existing account on the destination chain). One
218// purpose of the "chain claim id" is to prevent transaction replay. For this
219// transaction, we use a different mechanism: the accounts must be claimed on
220// the destination chain in the same order that the `XChainCreateAccountCommit`
221// transactions occurred on the source chain.
222//
223// This transaction can only be used for XRP to XRP bridges.
224//
225// IMPORTANT: This transaction should only be enabled if the witness
226// attestations will be reliably delivered to the destination chain. If the
227// signatures are not delivered (for example, the chain relies on user wallets
228// to collect signatures) then account creation would be blocked for all
229// transactions that happened after the one waiting on attestations. This could
230// be used maliciously. To disable this transaction on XRP to XRP bridges, the
231// bridge's `MinAccountCreateAmount` should not be present.
232//
233// Note: If this account already exists, the XRP is transferred to the existing
234// account. However, note that unlike the `XChainCommit` transaction, there is
235// no error handling mechanism. If the claim transaction fails, there is no
236// mechanism for refunds. The funds are permanently lost. This transaction
237// should still only be used for account creation.
239{
240public:
242
244 {
245 }
246
247 static NotTEC
248 preflight(PreflightContext const& ctx);
249
250 static TER
251 preclaim(PreclaimContext const& ctx);
252
253 TER
254 doApply() override;
255};
256
258
259//------------------------------------------------------------------------------
260
261} // namespace ripple
262
263#endif
State information when applying a tx.
BridgeModify(ApplyContext &ctx)
static constexpr ConsequencesFactoryType ConsequencesFactory
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
Class describing the consequences to the account of applying a transaction if the transaction consume...
Definition applySteps.h:58
static constexpr ConsequencesFactoryType ConsequencesFactory
static TER preclaim(PreclaimContext const &ctx)
XChainAddAccountCreateAttestation(ApplyContext &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
XChainAddClaimAttestation(ApplyContext &ctx)
static constexpr ConsequencesFactoryType ConsequencesFactory
static constexpr ConsequencesFactoryType ConsequencesFactory
static TER preclaim(PreclaimContext const &ctx)
XChainClaim(ApplyContext &ctx)
static NotTEC preflight(PreflightContext const &ctx)
TER doApply() override
XChainCommit(ApplyContext &ctx)
static TxConsequences makeTxConsequences(PreflightContext const &ctx)
static constexpr ConsequencesFactoryType ConsequencesFactory
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static constexpr ConsequencesFactoryType ConsequencesFactory
static TER preclaim(PreclaimContext const &ctx)
XChainCreateAccountCommit(ApplyContext &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
static constexpr ConsequencesFactoryType ConsequencesFactory
static NotTEC preflight(PreflightContext const &ctx)
XChainCreateBridge(ApplyContext &ctx)
static constexpr ConsequencesFactoryType ConsequencesFactory
XChainCreateClaimID(ApplyContext &ctx)
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
constexpr size_t xbridgeMaxAccountCreateClaims
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:80
State information when preflighting a tx.
Definition Transactor.h:35