How does the Storage Mechanism in DFINITY works?

I was exploring the Dfinity Internet Computer’s working & structure, gone through SDK Docs also. Looks promising to me, but I was unable to find more details about the storage mechanism.

. Can I get some more details about how the data is stored on Dfinity’s Network?

. And can I read data/state directly from Dfinity’s Internet Computer or Subnet, without interacting with canister?

Any help will be much appreciated.
Thanks!

3 Likes

Canisters are a fundamental concept on the platform. So actually, storing to and reading data from the Internet Computer is storing to and reading data from canisters.

All your data is persisted in the data structures that you define in your code, anything from simple arrays to hashmaps or any other structure you want to build, the platform persists the state of these structures for you, it’s very similar to the way data sits in memory on your local machine while a program runs and can be thought of in exactly the same way. You could build out any storage setup you need to. I’d expect many specialised storage services and libraries for specific types of data will be written.

As to what canisters are: you’d define your data structures, write the code that populates them, and give it an interface to expose it. The canisters encapsulate all of this. There’s a great article on them here which includes some other ways you might approach thinking about them: https://medium.com/dfinity/software-canisters-an-evolution-of-smart-contracts-internet-computer-f1f92f1bfffb

It’s a very flexible approach, canisters are used across the platform itself as a fundamental construct, native platform features like the governance system and token ledger are canisters themselves.

3 Likes

Hi @Ori,

Than you for the details.

So, is there a way in Dfinity that allows us to read the states from canisters, without programmably sending a query transaction? Just like Ethereum does not require sending a transaction to read the account states, instead we can passively read the blockchain data.

Will there be a native tool/node API calls to help accessing the states?

Thanks!

Hi amz,

Updates and queries don’t require transactions - you interact with them like you would a server. Currently, we have Rust and JavaScript agents that will allow you to make your calls to a canister.

For nodejs, you’d want to install https://github.com/dfinity/agent-js. For more info, check out our docs! Write code for the Internet Computer :: Internet Computer

2 Likes

Hi kpeacock,

Thanks for your feedback, then how will the history be maintained for state changes of a canister? And what type of calls will raise the transactions then?

The state is stored in memory and managed through consensus. In Motoko, it’s as simple as assigning it to a stable variable. Calls simply are not transactions, and there won’t be a list of transactions for your canister unless you choose to add one for your particular use case.

Like Ori mentioned, the Internet Computer model is new technology, and has different architecture from existing blockchains. You can just write application logic with our tooling and run it on the Internet Computer. We abstract the consensus logic of the replica out for you. Definitely look forward to the Genesis talks and take a look through our documentation if you’re interested in the project!

4 Likes

Hi Kyle,

If the state is stored in memory, what would happen if all nodes happen to go down at the same time? Do we lose everything, and is it recoverable?

I know for example in Ethereum the community could rebuild the whole blockchain state from a single node. Would something like this be possible through the Internet Computer, or should we back up important data to other networks such as Ethereum?

No, the goals of the Internet Computer aren’t compatible with all data and all applications being backed up to every node. You couldn’t imagine the entirety of AWS somehow being backed up to each server, and the same would be impossible for the IC

Your canister data will be distributed geographically and among independent node providers, so that even if multiple nodes go down, your application will safely continue operating and will automatically assign new nodes to bring you back to full operation

4 Likes

I am new to this forum… but this project seems interesting…

But okay, @kpeacock what your saying though, is that the smart contract itself is not immutable, and the consensus relies on the number of nodes hosting your smart contract? How can I as a developer, be sure that I am getting correct data from the smart contract, when so few nodes are actually involved in the functions of the computation? What assures that the nodes will be honest actors? 50% of nodes hosting my smart contract? Or what?

I just can’t get my head around, how this could work with any current tokens, like a ERC20 token, without some type of immutable record somewhere? What I actually want to build is a ERC20 token right now on this, if this is possible, I highly suggest you put out a sample ERC20 token… But that leads me back to the original question, Is this even possible without a immutable record?

As of right now, this seems like it would be more useful in API development and things that are more centralized currently, making them slightly more decentralized, but not in tokens? What am I missing here?

2 Likes

Re example token implementations, you could take a look at some of these:

https://github.com/enzoh/motoko-token
https://github.com/flyq/motoko_token
https://github.com/ccyanxyz/motoko-token

1 Like

Thanks @ori that’s great there is some examples of ERC20. Okay so the ERC20 token is a canister, I get that. So, lets say I create and deploy a ERC20 canister, you are saying the canister lives on only a few of the Internet Computer nodes, but 1.)What incentive does a node have to host my canister? and 2.)What assures the ERC20 nodes are honest players? 50% of the ERC20 canister nodes, or 50% of all Internet computer nodes? The difference between a few nodes, and thousands of nodes involved in the consensus makes a huge difference to the viability of ERC20 tokens on this project, so really need to understand this… Thanks

1 Like

Do a bunch of canisters continuously randomly download data to verify that the data stored is correct? This is done centrally in storj, wouldn’t it be super expensive in a decentralised way? Otherwise storj would have already done it by now?

Hi Kyle - is there a mechanism for restoring Canister data that is assigned in stable variables should it be lost - for example if you install without specifying the upgrade option?

1 Like

I’m intrigued by the conversation thus far! Is @kpeacock or any other contributor able to help shed some light on some of these pending questions?

2 Likes

Our plan is to offer a tool that allows you to download the full state of canisters to test out upgrades locally and restore from backups

3 Likes