Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to execute Transactions

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

In this article, the editor introduces "how to implement Transactions" in detail, the content is detailed, the steps are clear, and the details are handled properly. I hope this "how to implement Transactions" article can help you solve your doubts.

What is Transactions?

We mentioned that Libra is a distributed ledger, which stores the status of the ledger. From the state of the ledger, we can get the financial situation of each account and the corresponding resources stored.

And the state of the account is changed by executing Transactions.

User-defined Transactions is written through Move. At present, Libra is in an early version, and only limited features are open to the Move language (as users cannot customize resource types, etc.), but with the development of Move, I believe that the Move language will get more functional support.

Basic conditions for Transactions operation

In Libra, we run Transactions, which contains the following basic conditions:

The initial state of the ledger. All verifier nodes must accept the initial state of the account and perform subsequent verification operations on top of that initial state.

In the initial state of the account book, we need to define the core components of Libra (such as: account logic, transaction verification, verifier choice, Libra coins, etc.), these core components are in the form of Move modules.

Similarly, to ensure the execution of the transaction, we also need an initial account and an initial authentication node, which need to be defined in the initial state.

For simplicity, let's assume that the initial state of the account is empty, and then generate the modules mentioned above by executing a Transaction T0. Note that T0 here is a special transaction, it is different from ordinary transactions, it can only be achieved through configuration.

The certainty of the transaction. All transactions for Libra must be confirmed and repeated. That is, if you know the input of a given transaction, you must get the same output.

I also mentioned functional programming in the previous article, which is very similar to functional programming. The deal doesn't have any side effects. We can get the same ledger as the current ledger by re-executing the history of the transaction.

Measurable. Like other blockchains, Libra introduces the concept of gas to prevent DDOS attacks. Each transaction must cost a certain amount of gas, which can effectively prevent invalid transactions from occurring.

Libra's gas is a little different from other blockchain gas in that Libra's gas is only used to reduce the possibility of the system running under high load, and Libra's gas costs very little for normal transactions.

Gas includes gas price and number of gas. The verification node will give priority to the transaction with high gas price and discard the transaction with low gas price, which can effectively prevent the system from running under high load.

Similarly, we also have a maximum number of gas. If the transaction execution exceeds the maximum number of gas, the Libra virtual machine stops execution, and the transaction result is not written to the account state, but is recorded in the transaction record.

Asset characteristics. We know that Libra coins are linked to real-world money, so Libra coins must not be repeated, lost, or used without authorization. These features are realized by Move virtual machine.

The structure of Transactions

In Libra, a Transaction is a signed data that contains the following:

The sender's address. The address of the sender of the transaction. VM can obtain the serial number, authentication key and balance of the address by reading the LibraAccount.T resources in the address.

Sender public key. The private key that matches the public key is used to sign the transaction. The authentication key in the LibraAccount.T resource mentioned above is the hash value of the public key.

program. The program is a script code for Move bytecode and may also include a list of required parameters.

Maximum number of gas. The maximum number of gas allowed by VM.

serial number. The serial number is an unsigned integer, and the serial number of the account is incremented by 1 after each transaction. Serial numbers are mainly used to prevent replay attacks.

Execute Transactions

Generally speaking, there are six steps to performing a Transactions.

Check the signature. The signature mainly checks whether the Transaction matches the sender's public key and the actual data.

Run prologue. The main purpose of running the prologue phase is to check the sender of the transaction (whether there are enough Libra coins) and whether the transaction is a replay transaction. All the functions are realized through the prologue process of the LibraAccount module.

Validate transaction scripts and modules. VM uses the move bytecode validator to verify that the scripts and modules of the transaction are valid (type safety, reference security, resource security, etc.).

Release module. All the modules in the program will be posted to the account of the initiator of the transaction. Note: the name of the module must be unique, or the deal will fail.

Run the transaction script. VM builds the script parameters and runs the transaction script. If the transaction is successful, the transaction and related events will be written to the book status. If the transaction fails, the state of the books will not change.

Run epilogue. Finally, VM runs epilogue to calculate the corresponding gas and subtract the corresponding value, and increase the serial number of the sender account. Like prologue, epilogue is a process of the LibraAccount module.

Read here, this "how to implement Transactions" article has been introduced, want to master the knowledge of this article also need to practice and use to understand, if you want to know more about the article, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report