1

From the document, I should save data in the Multi-Index DB, I want to know: Does it mean the data is saved into the block chain if I save the data in the DB? If yes, how the data is saved into block chain from the DB? Is there tech detail to explain how this is done?


Thanks for your reply! I am still a little confusing about the relationship. We use smart contract by pushing actions, and action should use DB API to persistent its state to DB. Let's say I push an action and the action save its state to DB, but when the state/action is written to block chain? Is it written to block chain after some BP confirm the action?

From my understanding, the DB is an in-memory DB. If the machine that runs the DB crashed, how to restore the DB? replay all actions from the beginning? If it's true, this will be a very long time to restore the DB.

1
  • the state is never written to the blockchain; it's just in-memory. yes, if the machine crashes and there are no immediate backups available, one would have to replay all actions from the beginning. in practice, BPs will have backups taken regularly of the state and multiple nodes running in parallel ready to swap in case one fails
    – confused00
    Commented Sep 21, 2018 at 3:37

1 Answer 1

1

Does it mean the data is saved into the block chain if I save the data in the DB?

No, the data does not need to be saved on the blockchain to be in the persistence database. The data is loaded in the EOSIO DB when the contract is processed, and it's stored in an off-chain database that active nodes use to have read/write access to the state.

Thus, the relationship between the multi-index DB and the blockchain is that processing all transactions in the blockchain will recreate the persistence database at any point even if the data itself is not stored in the blockchain.

An overly simplified parallel would be that the blockchain stores 1+1 while the EOSIO DB stores 2 in RAM. You can compute the state if you replay the blockchain and process all transactions, but storing the current state in RAM allows you to access required data efficiently.

Is there tech detail to explain how this is done?

This article in the official docs explains some of the concepts underpinning the EOSIO DB. Excerpt:

EOSIO provides a set of services and interfaces that enable contract developers to persist state across actions, and consequently transactions, boundaries. Without persistence, state that is generated during the processing of actions and transactions will be lost when processing goes out of scope.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.