Understanding registers

I’m not sure I understand registers.

When I read the developer docs, I understand files are immutable, and registers are mutable.

I have made a little blocks/tetris like game people can see it by running:

$ ant file download 261f85f041460702dd3598e543808ff9835e748786999fced5c1803533eac644 marks-blocks-game

This works perfectly, however if I want to change anything I must upload a new file.

So my understanding is we have registers, that can be mutated, and as such I should be able to make a register point marks-blocks-game to the file id, and update this if I upload a new version/file.

So I tested this out and made a register.

$ ant register create autonomi-blocks-game testing

🔗 Connected to the Network
Creating register with name: autonomi-blocks-game
✅ Register created at address: af273bfee32503d70fabf40bbf6a12e57af3a1656948e42e3f0905939e640eb5bc8363c6f5a6638a455c1be79d1c8ec6
With name: autonomi-blocks-game
And initial value: [testing]
Total cost: 0.00000000000000000000022411078500 AttoTokens

Next, I try and read that register, and I do get the value I expect:

$ ant register get --name autonomi-blocks-game
🔗 Connected to the Network
Getting register with name: autonomi-blocks-game
✅ Register found at: autonomi-blocks-game
With value: [testing]

So, next up, I try and update it to my current game version:

$ ant register edit --name autonomi-blocks-game "261f85f041460702dd3598e543808ff9835e748786999fced5c1803533eac644"

🔗 Connected to the Network
Error:
   0: Invalid register value length: 64, expected something within 32 bytes

Location:
   ant-cli/src/commands/register.rs:89

This is my first surprise/problem. Reading the docs, I can indeed see the register is limited to 32 bytes, but the files seem to have 64 byte hashes. I’m not sure why? I’m I misunderstanding the point of the register?

But I also just wanted to see the register mutating, so I decided to update it to something smaller anyway.

$ ant register edit --name autonomi-blocks-game "edit-test"

🔗 Connected to the Network
Attempting to update register at autonomi-blocks-game with new value: edit-test
✅ Successfully updated register
With value: [edit-test]
Total cost: 0.00000000000000000000000055883640 AttoTokens

It seems like it works. Woohoo!

But then I try and read the register again:

$ ant register get --name autonomi-blocks-game

🔗 Connected to the Network
Getting register with name: autonomi-blocks-game
✅ Register found at: autonomi-blocks-game
With value: [testing]

But I seem to get the original value of the register.

So I guess, my TL;DR; questions are:

  1. Why are file hashes 64 bytes but registers are only allowed values of a max 32 bytes?
  2. Why did updating the value of a register then reading it again not show the new value?
6 Likes
  1. Is a matter or different formats. You need to convert the ASCII 64 bytes to our 32 byte representation. I have helped functions in dweb-lib for this kind of thing but would have to look then up to explain better.

Can’t say about 2, might be a bug. I wrote my own version of Registers (History<T>) rather than use Autonomi’s. It works but it’s not pushed to github yet.

8 Likes

Ahh I see, that makes sense. Thanks for the help @happybeing

The hex seems to be working, I’ve added a PR to add a --hex flag:

I’ve also raised a github issue for the edits not persisting:

5 Likes

I’ve just pushed dweb-lib to my github which incudes a more capable version of registers, and for which the dweb CLI provides handy ‘inspect’ subcommands (for pointer, graph entry, history etc).

I’ve not pushed to crates.io yet but can do so if you want to use anything.

A sample of dweb commands (on a local network)…

dweb --help

dweb --help`
a web publishing and browsing app for Autonomi peer-to-peer network

Usage: dweb [OPTIONS] [COMMAND]

Commands:
  serve               Start a server to allow you to view Autonomi websites in a web browser
  awesome             Open a browser with the awesome website of awesome Autonomi websites
  estimate            Estimate the cost of publishing or updating a website
  publish-new         Publish a directory or website for the first time
  publish-update      Update a previously published directory or website and preserve older versions on Autonomi
  inspect-history     Print information about a history of data stored on Autonomi
  inspect-graphentry  Print information about a graph entry stored on Autonomi
  inspect-pointer     Print information about a pointer stored on Autonomi
  inspect-files       Print information about files in a directory on Autonomi
  help                Print this message or the help of the given subcommand(s)
[snip]

dweb inspect-pointer

$ dweb --local inspect-pointer 1827dac5b639f754acb0bb6a0234c4d563d0340c314a0150e5ac3aace31ea75a`
Dweb Autonomi client initialising...
⠐ Connecting to a local Autonomi Network...                                                                                                                            Connected to the Network
🔗 Connected to the Network                                                                                                                                            pointer     : 1827dac5b639f754acb0bb6a0234c4d563d0340c314a0150e5ac3aace31ea75a
  target    : eaa48381fccffee5ca38838b941d0eb559a948031c3085555f4b9c16e4db5b3c
  counter   : 4

dweb inspect-history

$ dweb --local inspect-history -fe '1:1' --include-files -p 9188ec4c126c2fdcaceaf4a50ab18e28446b992ef1c5061789ed7af7e844343e71786cb3f69c10d6e98d6e018235709d`
Dweb Autonomi client initialising...
⠂ Connecting to a local Autonomi Network...                                                                                                                            Connected to the Network
🔗 Connected to the Network                                                                                                                                            history address  : 9188ec4c126c2fdcaceaf4a50ab18e28446b992ef1c5061789ed7af7e844343e71786cb3f69c10d6e98d6e018235709d
  type           : ebeabe6c1dccaca8865d0a6fcc52a82f117d0be1028a3e6212faced9858a0878
  size           : 4
  pointer address: 1827dac5b639f754acb0bb6a0234c4d563d0340c314a0150e5ac3aace31ea75a
  graph root     : 2201629d3a1972d10382c7e1c3f2d3da7dc57ba4efa806e3cb44c897f678fa62
  graph head     : eaa48381fccffee5ca38838b941d0eb559a948031c3085555f4b9c16e4db5b3c
  entries 1 to  1:
DEBUG stepping forwards: index 1 > 0 iter_index
    entry    1:
    address   : 0a22433954ae00c3d03ff3747daf6826e4e91160441a6f64cc28e989bc9548b4
      owner      : 849e84aae20be7e4d52c26f11c5239e7004edd81a3eb7dc8757a5795af6116cbfb922b2e4165746e21af9c2eaeaa4f2a
      parents    : [2201629d3a1972d10382c7e1c3f2d3da7dc57ba4efa806e3cb44c897f678fa62] 
      descendents: [1d77973911544dc73ab35fa94b15d5e4146555959aef3daaae3af2ea46337a0a] 
      content    : 5ccfb93b341dc3a4289455b492d2297c58565e7fd3854eaa2fe468cbb50bf633
      signature  : 8f80cea7fb80ab9a9e9ec28dd182531f8358a0e7cb2f8d661f145d0dbd2af972d8034bb45d81f3f52111ed71409b14231914ee723612137ea6be0d318148beebc709b0a08621db6778ca40f7f6a0d82f45a30f4ed145c10ce687ad43acc1a7a0
    entry 1 - fetching content at 5ccfb93b341dc3a4289455b492d2297c58565e7fd3854eaa2fe468cbb50bf633
DEBUG directory_tree_download() at 5ccfb93b341dc3a4289455b492d2297c58565e7fd3854eaa2fe468cbb50bf633
DEBUG autonomi_get_file_public()
DEBUG calling client.data_get_public()
DEBUG Ok() return
Retrieved 402 bytes
      published  : 2025-02-16 12:21:25.954526336 UTC
      directories: 1
      files      : 4
      total bytes: 236226
      fe0d0b9bb2ac1bc85bc410a59ea7c0e462e420c1540e7a860239bba68c820f4f "/another-ant.png"
      b1ccf5989cc287532cae5a98adabc03bfc2cd95368c09e41dd066335a5e2a8f9 "/index-ants.png"
      d5b4bf77372fbd4db9525b5c8ece06444dd22ed236feff739d476c3fa44b5644 "/index.html"
      ffd5982fdf397f6ee4e823dbc82ae8c7b4f0bc86dfc8068cfe54b855311c8cfd "/more-ants.html"
6 Likes

This looks really cool @happybeing. Tried it out and ran the serve command. Opening 127.0.0.1:8080 showed hello world, but I’ve no idea how to actually serve a site. Is that feature woirking yet? Could you document it to explain how to view a website in the README or something?

I’ve tried a bunch of those hashes like this in Chrome:

http://127.0.0.1:8080/5ccfb93b341dc3a4289455b492d2297c58565e7fd3854eaa2fe468cbb50bf633
http://127.0.0.1:8080/5ccfb93b341dc3a4289455b492d2297c58565e7fd3854eaa2fe468cbb50bf633/index.html
http://127.0.0.1:8080/eaa48381fccffee5ca38838b941d0eb559a948031c3085555f4b9c16e4db5b3c
http://127.0.0.1:8080/eaa48381fccffee5ca38838b941d0eb559a948031c3085555f4b9c16e4db5b3c/index.html

And loads more.

But just get:

test-default-route '/':
uri: /5ccfb93b341dc3a4289455b492d2297c58565e7fd3854eaa2fe468cbb50bf633/index.html
method: GET
1 Like

Hey, that’s awesome, thanks for trying it out.

To view will need to publish something first (e.g. to a local testnet using the --local option), and then you can visit it via the dweb API, and set a name for it. The API is minimal right now but you can see various options in dweb-cli/src/services/api/dweb_v0.rs (and other services under services).

You will also need to set up a local DNS to redirect some domains to localhost. I’m using DNSmasq to redirect everything with a domain ending in -dweb.au to localhost using the following in /etc/dnsmasq.conf:

address=/*-dweb.au/127.0.0.1

DNSmasq is available for Windows and Mac too, but I’ve only tried Linux. I think it should be possible to do this using browser proxy settings but haven’t tried it yet.

If you are not on Linux and succeed with any of those feel free to send me instructions for the README.

To proceed, run dweb serve in a terminal and then, supposing you uploaded a website (see dweb publish-new --help) and the output to the command line contains:

CONTENT PUBLISHED (version 1). Cost 0.00000000000000000000000000000237 ANT.
All versions available at HISTORY-ADDRESS:
85a652d4f206d5a8868784b2e9f0ac4715f154945154f5d1c8305524c433729feae8e3a21d95d70dc4e7df402f7c2912

Grab the HISTORY-ADDRESS and insert it into a link like the following.

http://api-dweb.au:8080/dweb/v0/dwebname/register/smartypants/85a652d4f206d5a8868784b2e9f0ac4715f154945154f5d1c8305524c433729feae8e3a21d95d70dc4e7df402f7c2912

This should register the DWEB-NAME ‘smartypants’ with that address so you won’t need to type it again (until you restart the server). It will then redirect to a shorter URL and load the most recently published content.

If it was published but not updated yet it will redirect to http://v1.smartypants.www-dweb.au:8080/. But if you had published once and updated twice you would get the content at http://v3.smartypants.www-dweb.au:8080/ (version 3).

Leave of the ‘vN.’ and it will load the most recent version.

From there on you can edit the version part of the URL to ‘v1’ or ‘v2’ and so on. In future these names will be stored on Autonomi, shared between folks and so on to provide a decentralised alternative to DNS, but for now they are not persistent.

Let me know how you get on!

I will of course be doing this but not until it is ready for the live network. I’m working on one more thing before trying that.

2 Likes