当前位置:网站首页>Exploring the source code of Boca Cross Chain Communication: Elements
Exploring the source code of Boca Cross Chain Communication: Elements
2022-06-30 12:53:00 【InfoQ】
- Strong interoperability
- Excellent scalability
- Strong universality
- Heterogeneous cross chain has strong consistency
- Unique sharing security mechanism , Good safety
- Participants in the communication
- The content transmitted in the communication process
- How the communication process is implemented , Communication protocol
Boca's cross chain participants
- Blockchain
- Intelligent contract
- Transfer bridge
- even to the extent that pallets.
The contents of Boca's cross chain transmission
XCM
Cross-Consensus Message Format Cross consensus message format Xcm<Call>enum#[scale_info(bounds(), skip_type_params(Call))]
pub enum Xcm<Call> {
//...snippets
WithdrawAsset(MultiAssets),
ReserveAssetDeposited(MultiAssets),
ReceiveTeleportedAsset(MultiAssets),
//...snippets
}
Tuple Struct#[scale_info(bounds(), skip_type_params(Call))]
pub struct Xcm<Call>(pub Vec<Instruction<Call>>);
Instruction<Call>enum//....snippets
#[scale_info(bounds(), skip_type_params(Call))]
pub enum Instruction<Call> {
WithdrawAsset(MultiAssets),
ReserveAssetDeposited(MultiAssets),
ReceiveTeleportedAsset(MultiAssets),
//....snippets
}
enumInstruction<Call>Instruction<Call>Instruction<Call>WithdrawAssetoriginInstruction<Call>XCVM
xcm-executorXcmExecuteorpub struct XcmExecutor<Config: config::Config> {
pub holding: Assets,
pub origin: Option<MultiLocation>,
pub original_origin: MultiLocation,
pub trader: Config::Trader,
/// The most recent error result and instruction index into the fragment in which it occurred,
/// if any.
pub error: Option<(u32, XcmError)>,
/// The surplus weight, defined as the amount by which `max_weight` is
/// an over-estimate of the actual weight consumed. We do it this way to avoid needing the
/// execution engine to keep track of all instructions' weights (it only needs to care about
/// the weight of dynamically determined instructions such as `Transact`).
pub total_surplus: u64,
pub total_refunded: u64,
pub error_handler: Xcm<Config::Call>,
pub error_handler_weight: u64,
pub appendix: Xcm<Config::Call>,
pub appendix_weight: u64,
_config: PhantomData<Config>,
}
XcmExcutorexecuteimpl<Config: config::Config> XcmExecutor<Config> {
//...snippets
pub fn execute(&mut self, xcm: Xcm<Config::Call>) -> Result<(), ExecutorError> {
//...snippets
if let Err(e) = self.process_instruction(instr) {
*r = Err(ExecutorError { index: i as u32, xcm_error: e, weight: 0 });
},
//...snippets
}
executeprocess_instructionprocess_instructionfn process_instruction(&mut self, instr: Instruction<Config::Call>) -> Result<(), XcmError> {
match instr {
//...snippets
TransferReserveAsset { mut assets, dest, xcm } => {
let origin = self.origin.as_ref().ok_or(XcmError::BadOrigin)?;
// Take `assets` from the origin account (on-chain) and place into dest account.
for asset in assets.inner() {
Config::AssetTransactor::beam_asset(asset, origin, &dest)?;
}
let ancestry = Config::LocationInverter::ancestry();
assets.reanchor(&dest, &ancestry).map_err(|()| XcmError::MultiLocationFull)?;
let mut message = vec![ReserveAssetDeposited(assets), ClearOrigin];
message.extend(xcm.0.into_iter());
Config::XcmSender::send_xcm(dest, Xcm(message)).map_err(Into::into)
}
//...snippets
}
//...snippets
},
Boca cross chain communication protocol
- XCMP, Full name Cross-Chain Message Passing, namelyCross chain message protocol, The agreement uses Merkle Tree to ensure communication security verification , And based on this, there is a simple queuing system ; stay XCMP During the execution of the agreement , The relay chain will only cross chain transaction related metadata (metadata) Store in hash form , Therefore, the occupied resources and execution efficiency are extremely high . XCMP There are two forms :
- Direct communication ,xcm Message data is transmitted directly between parallel chains , For a relay chain, there can only be one “ Notify ” The action of , This method is highly scalable , It is still under development .
- Repeater communication ,That is, the relay chain is used to transmit , Specifically, through VMP To achieve , VMP See below for details .
- XCMP-Lite, namely HRMP(Horizontal Relay-routed Message Passing Horizontal relay routing messagingagreement ). because XCMP The direct communication mode of China Pingxing chain is still under development , So at the moment Polkadot and Kusama On the relay chain , It uses HRMP As a transition at this stage . You can see from the above , HRMP In the message delivery of , The data is directly expressed in Vec
- HRMP And XCMP Use the same interfaces and functions , But the biggest difference is HRMP Store all message contents in the trunk chain , Therefore, the occupied resources and execution efficiency are far less than XCMP. Here are HRMP In the source 2 Message structure code , Also for ease of understanding , Here we do some simplification :
pub struct InboundHrmpMessage<BlockNumber = crate::BlockNumber> {
pub sent_at: BlockNumber,
pub data: sp_std::vec::Vec<u8>,
}
pub struct OutboundHrmpMessage<Id> {
pub recipient: Id,
pub data: sp_std::vec::Vec<u8>,
}
This approximation “ Plaintext ” To store all message data .
- VMP (Vertical Message Passing Vertical messaging protocol ) ,VMP It's actually a general term , Used with HRMP Of “ level ” Contrast ; HRMP Of H namely “Horizontal level ”, It refers to the communication between parallel chains ; andVMPOf V namely “Vertical vertical ” It mainly refers to the communication between the relay chain and the parallel chain , VMP contain 2 Agreements :
- UMP (Upward Message Passing Uplink messaging protocol ): The message is passed from the parallel chain to the relay chain , be called “ Pass up ”, Since the contents of messages sent from each parallel chain to the relay chain may vary greatly , therefore
UMPThe module mainly provides a module namedUmpSinkOftraitTo unify constraints . Use trait To unify the benefits of constraints , It is to give each parallel chain as much flexibility as possible .
pub trait UmpSink {
fn process_upward_message(
origin: ParaId,
msg: &[u8],
max_weight: Weight,
) -> Result<Weight, (MessageId, Weight)>;
}
impl UmpSink for () {
fn process_upward_message(
_: ParaId,
_: &[u8],
_: Weight,
) -> Result<Weight, (MessageId, Weight)> {
Ok(0)
}
}
- **DMP (Downward Message Passing Downlink messaging protocol **) : Passing messages from the relay chain to the parallel chain , be called “ Pass down ”; This can relatively unify the format , So the source code defines a `DownwardMessage` type , The essence is a `Vec<u8>` type , And use `InboundDownwardMessage` The structure is wrapped , So that it can be put in the queue for processing
pub type DownwardMessage = sp_std::vec::Vec<u8>;
#[derive(Encode, Decode, Clone, sp_runtime::RuntimeDebug, PartialEq, TypeInfo)]
#[cfg_attr(feature = "std", derive(MallocSizeOf))]
pub struct InboundDownwardMessage<BlockNumber = crate::BlockNumber> {
pub sent_at: BlockNumber,
pub msg: DownwardMessage,
}
summary
Reference material
- https://wiki.polkadot.network/docs/learn-crosschain
- https://research.web3.foundation/en/latest/polkadot/XCMP/index.html
- https://cointelegraphcn.com/news/is-cosmos-and-polkadots-cross-chain-the-same-thing ?????
- https://medium.com/polkadot-network/xcm-the-cross-consensus-message-format-3b77b1373392
- https://github.com/paritytech/xcm-format
边栏推荐
- Dataworks synchronizes maxcomputer to sqlserver. Chinese characters become garbled. How can I solve it
- Today in history: Microsoft acquires PowerPoint developers; SGI and MIPS merge
- Machine learning notes - Introduction to autocorrelation and partial autocorrelation
- 项目中遇到一个有趣的事情
- Basics of golang -- the difference between slicing and array
- Efficient elliptic curve point addition and multiplication in scrypt
- ERROR: Cannot uninstall ‘PyYAML‘. It is a distutils installed project and thus we cannot accurately
- Substrate 源码追新导读: Call调用索引化, 存储层事物化全面完成
- 写信宝小程序开源
- 数据仓库建设之确定主题域
猜你喜欢

【 surprise】 la vitesse de téléchargement de Thunderbolt n'est pas aussi rapide que celle de la machine virtuelle

uniapp支付之APP微信支付unicloud版(附源码)

电机控制park变换公式推导

Today in history: Microsoft acquires PowerPoint developers; SGI and MIPS merge

FlinkSQL自定义UDATF实现TopN

Dark horse notes - common date API

Machine learning notes - Introduction to autocorrelation and partial autocorrelation

Open source of xinzhibao applet

Basic interview questions for Software Test Engineers (required for fresh students and test dishes) the most basic interview questions

资源变现小程序开通流量主教程
随机推荐
Flink sql控制台,不识别group_concat函数吗?
elementui中清除tinymce富文本缓存
Discussion on JMeter operation principle
[one day learning awk] array usage
顺应媒体融合趋势,中科闻歌携手美摄打造数智媒宣
[Select] resource realization information, news, we media, blog applet (can be drained, open traffic master, with PC background management)
dataworks 同步maxcomputer 到sqlserver ,汉字变乱码了,请问怎么解决
微信小程序报错:TypeError: Cannot read property ‘setData‘ of undefined
Questionnaire star questionnaire packet capturing analysis
Basics of golang -- the difference between slicing and array
Motor control Clarke( α/β) Derivation of equal amplitude transformation
Basic interview questions for Software Test Engineers (required for fresh students and test dishes) the most basic interview questions
Terms related to JMeter performance test and performance test passing standards
JMeter learning notes
Visual Studio配置Qt并通过NSIS实现项目打包
波卡跨链通信源码探秘: 要素篇
【OpenGL】OpenGL Examples
黑马笔记---常用日期API
黑马笔记---包装类,正则表达式,Arrays类
uniapp支付之APP微信支付unicloud版(附源码)