stacks-network / stacks-core

The Stacks blockchain implementation
https://docs.stacks.co
GNU General Public License v3.0
3.01k stars 664 forks source link

[clarity] signer StackerDB contract for pox-4 #3957

Open jferrant opened 11 months ago

jferrant commented 11 months ago

For signers to communicate with each other, they need to have access to a deployed stacker db contract.

A stackerdb contract must contain the following two functions (update accordingly):

        ;; stacker DB
        (define-read-only (stackerdb-get-signer-slots)
            (ok (list
                {
                    signer: 'ST24GDPTR7D9G3GFRR233JMWSD9HA296EXXG5XVGA,
                    num-slots: u10
                }
                {
                    signer: 'ST1MR26HR7MMDE847BE2QC1CTNQY4WKN9XDKNPEP3,
                    num-slots: u10
                }
                {
                    signer: 'ST110M4DRDXX2RF3W8EY1HCRQ25CS24PGY22DZ004,
                    num-slots: u10
                }
                {
                    signer: 'ST69990VH3BVCV39QWT6CJAVVA9QPB1715HTSN75,
                    num-slots: u10
                }
                {
                    signer: 'STCZSBZJK6C3MMAAW9N9RHSDKRKB9AKGJ2JMVDKN,
                    num-slots: u10
                }
                )))

        (define-read-only (stackerdb-get-config)
            (ok {
                chunk-size: u4096,
                write-freq: u0,
                max-writes: u4096,
                max-neighbors: u32,
                hint-replicas: (list )
            }))

The stackerdb contract is read and loaded to each stacks node once at the start of a reward cycle.

The signer's stackerdb would be partitioned into two sets of slots: one for the current stackers, and a corresponding one for the new stackers. Which partition a stacker gets assigned to would be a function of reward cycle count. For example, if the reward cycle is even, the current stackers use the first partition and the new stackers use the second partition. But if it's odd, then the current stackers would use the second partition and the new stackers would use the first.

As the signer stackerdb contract config is only read and loaded into a stacks node once per reward cycle, the new set of stackers for reward cycle N + 1 MUST overwrite the stackers N - 1 PRIOR to the end of reward cycle N so that at the START of reward cycle N+1, the contract contains the stackers N and stackers N+1.

Related to https://github.com/stacks-network/stacks-blockchain/issues/3948

setzeus commented 11 months ago

Reviewing here for my own sake, "The StackerDB contract is read and loaded to each stacks node once at the start of a reward cycle" reads to me that each node loads a new StackerDB boot contract near the end of ever cycle.

Is that right? Or should we have a persistent StackerDB contract that is instead updated through a privileged contract such as PoX-4?

jferrant commented 11 months ago

Reviewing here for my own sake, "The StackerDB contract is read and loaded to each stacks node once at the start of a reward cycle" reads to me that each node loads a new StackerDB boot contract near the end of ever cycle.

Is that right? Or should we have a persistent StackerDB contract that is instead updated through a privileged contract such as PoX-4?

This means there is one persistent StackerDB contract that is updated through a privileged contract. It just means that the stacks nodes that have their databases running will at the start of every reward cycle make a read only contract call to the persistent stackers-signers-stacker-db contract and load the updated info.

setzeus commented 11 months ago

Latest update on #3977

setzeus commented 11 months ago

Latest update here: https://github.com/stacks-network/stacks-blockchain/tree/add-storage-contracts

setzeus commented 11 months ago

Focus has been on getting DR over the finish line, looping back next week.

setzeus commented 10 months ago

Latest here: https://github.com/stacks-network/stacks-blockchain/blob/add-storage-contracts/storage-contracts/storage-contracts/contracts/stacker-DB.clar

Periodically reviewing w/ Jacinta & Sayak.

setzeus commented 10 months ago

PR #4007 in stacks-blockchain now a WIP version of this.