Direct RC delegation documentation

in #rc2 years ago (edited)

Direct RC delegations

Forewords:

You may have heard about RC pools, direct RC delegations are not the same. RC pools got deprecated in favor of RC delegations. Although they are quite similar in name, their function is very different. If you're interested in the difference between the two see this post: https://peakd.com/rc/@howo/direct-rc-delegations-vs-rc-pools-and-tentative-direct-rc-delegations-spec

Direct RC delegations

Direct RC delegations are the simplest version of RC delegation you can think of:
Bob is out of RC, Alice has 200 RC, so she uses her posting key to delegate 100 RC to Bob. Bob now has 100 rc that he is free to use.

Now while this is a basic example, I'll dive into some more specifics.

Max RC vs RC

It's important to differentiate between the two resources we are dealing with:

Here I have 77 million RC out of 87 million max RC. When a user executes a direct RC delegation, they delegate max RC. This has two effects:

  • Once spent, the delegated RC will regenerate on the delegatee's account
  • Delegating RC will increase the amount of RC you regenerate. The more max RC you have the more you regenerate RC over time, in theory you could delegate 100 million RC on someone with 10k RC to make him regenerate his RC much more quickly and then undelegate. (Although this is unpractical due to the fact that undelegating burns unspent RC).

Constraints & details

  • You cannot delegate delegated RC, this is to avoid expensive chain computations.
  • You delegate max RC and RC, so you can't do a delegation when you are out of RC.
  • When undelegating, the delegator only gets his max RC back, all unspent RC is burned. The delegator will regenerate the RC over time.
  • Delegating is done over custom_json and requires posting authority (more on that later)
  • You can delegate to as many accounts as you want.
  • You can't delegate all your RC (and end up with 0 RC), you have to always keep the RC equivalent of the account creation fee (3 HIVE as the time of writing).
  • You can delegate up to 100 accounts in a single operation.

RC reserve

When an account is created, the account_creation_fee is burned (as the time of writing, 3 HIVE), that amount is converted in RC, this is why even 0 HP account have some RC. (this is also true for accounts created with account creation tokens).

This "RC reserve" is not delegatable, this is to prevent a bad actor from delegating all your RC away effectively soft-locking your account.

RC delegations in action

There is only one operation used for everything. delegate_rc the operations is sent in the form a custom json, here's an example where howo delegates 100 max RC to alice.

{
  "id": "rc",
  "json": [
    "delegate_rc",
    {
      "from": "howo",
      "delegatees": [
        "alice"
      ],
      "max_rc": 100
    }
  ]
}

I will be basing the rest of this guide using hive-js, all the examples, also note that all the keys in this example are from a testnet, they are worthless.

Creating an RC delegation

The parameters are pretty straightforward:

from: Person who delegates the max RC
delegatees: array of account names that you want to delegate to (max 100)
max_rc: max RC amount you want to delegate.

function delegate_rc(delegator, posting_key, delegatees, max_rc) {
    return new Promise(resolve => {
        const json = JSON.stringify(['delegate_rc', {
            from: delegator,
            delegatees: delegatees,
            max_rc: max_rc,
        }]);

        hive.broadcast.customJson(posting_key, [], [delegator], 'rc', json, function (err, result) {
            resolve(err)
        });
    });
}

Updating a delegation

Updating a delegation is done with the same operation, just input a different max RC amount and the delegation will be increased/reduced.

Keep in mind that if you reduce the delegation, the max RC will come back to you but the RC will be burned.

Deleting a delegation

Deleting a delegation is done by calling delegate_rc with max_rc set to 0.

Getting RC from an account

This api endpoint has existed since HF20 but has been updated with RC delegations, it's simply called by passing in an array of accounts

function get_rc(accounts) {
    return new Promise(resolve => {
        hive.api.call('rc_api.find_rc_accounts', {accounts: accounts}, function (err, result) {
            return resolve(result)
        })
    });
}
async function main() {
    let rc_accounts = await get_rc(["initminer", "miners"])
}

output is an array of rc_account objects, note the new fields: delegated_rc and received_delegated_rc

[
  {
    "account": "initminer",
    "rc_manabar": {
      "current_mana": 3153959569,
      "last_update_time": 1660535262
    },
    "max_rc_creation_adjustment": {
      "amount": "2020748973",
      "precision": 6,
      "nai": "@@000000037"
    },
    "max_rc": 3153959569,
    "delegated_rc": 150,
    "received_delegated_rc": 0
  },
  {
    "account": "miners",
    "rc_manabar": {
      "current_mana": 2020748983,
      "last_update_time": 1660535259
    },
    "max_rc_creation_adjustment": {
      "amount": "2020748973",
      "precision": 6,
      "nai": "@@000000037"
    },
    "max_rc": 2020748983,
    "delegated_rc": 0,
    "received_delegated_rc": 10
  }
]

Listing RC accounts:

If you don't have the full list, you can request the RC accounts:

function list_rc_accounts(start, limit) {
    return new Promise(resolve => {
        hive.api.call('rc_api.list_rc_accounts', {start:start, limit: limit}, function (err, result) {
            return resolve(result)
        })
    });
}

async function main() {
    let rc_accounts = await list_rc_accounts("initminer", 2)
}

The ordering is alphabetical, so you input the start and how many users you want to fetch (limited to 1000) and there you go, think of it as pagination.
If you reach the end of the 1000 and didn't find your account, put the last account as "start" and get the next 1000.

Listing all delegations

So this is where it gets a tad tricky, the start param is an array.

  • The first element of the array is from, who is delegating
  • The second element of the array is to, who is delegated to

The second parameter, limit is pretty self explanatory. it's limited to 1000 elements per query.

Both parameters are used for pagination.

If you want to fetch a specific delegation, fill both from and to
If you want to get all the delegations from an account, set from as the account and leave to as empty

If you only input from and reach the end of limit (for instance if an account delegated more than 1000 users), you can continue by inputting the last delegatee in the to field.

Here's a few examples:

function list_rc_direct_delegations(from, to, limit) {
    return new Promise(resolve => {
        hive.api.call('rc_api.list_rc_direct_delegations', {start:[from, to], limit: limit}, function (err, result) {
            return resolve(result)
        })
    });
}

async function main() {
    // List the first 100 delegations from initminer 
    await list_rc_direct_delegations("initminer", "", 100)
    // get the delegation from initminer to howo
    await list_rc_direct_delegations("initminer", "howo", 1)
    // List 100 delegations starting with the initminer -> howo delegation
    await list_rc_direct_delegations("initminer", "howo", 100)
}

The output is an array of delegation objects:

[
  {
    "from": "initminer",
    "to": "howo",
    "delegated_rc": 70
  },
  {
    "from": "initminer",
    "to": "alice",
    "delegated_rc": 70
  }
]

Important tidbit about the ordering, you may be confused that this list is not in alphabetical order, this is because under the hood, we index with account numbers, not account names.

So the reason why howo comes up before alice in this testnet, is because if you look at the get_account api call:

[{
    "id": 6,
    "name": "howo",
    ...
  },{
    "id": 7,
    "name": "alice",
    ....
  }
]

alice's id is 7 and howo's id is 6. If you want to get a bit more in depth, I talk about it in this issue (among other things): https://gitlab.syncad.com/hive/hive/-/issues/271

Note that due to technical limitations, it's not possible to only input to and get all the inbound delegations, this has to be built on an L2 api (eg: HAF/hivemind/hiveSQL).

Conclusion

I hope you found this documentation useful, if you want to check the direct RC delegation code yourself it's here: https://gitlab.syncad.com/hive/hive/-/merge_requests/245/diffs

I'll be glad to answer any questions that come up in the comments and hope to see a lot of use for rc delegations once hard fork 26 hits !

@howo


You can vote for our witness directly using Hivesigner here.

Sort:  

You can't delegate more than the RC equivalent of the account creation fee (3 HIVE as the time of writing).

I'm confused. You mean if I have 10K HIVE power I can only delegate a tiny amount of RC to any account because of this limit rule?

You can delegate max the RCs corresponding to 10k HP - 3 HIVE, as far as I understand it. The 3 HIVE is the reserve you can't touch. Anything else, you can delegate. Probably the wording is wrong in the post.

Pretty sure that's right.

Yes, my bad, edited the wording.

this is really strange for me as well; why this limitation? This isn't very helpful for minnows that will run out of RC when the limit is so low

This slipped past my re-read. there isn't such limitation all good :)

okay great to hear! that wouldn't have made any sense :D

any chance that RC pools will be integrated at some time?

Unlikely as direct RC delegation covers most of the cases.

You can delegate max the equivalent of the account creation fee (3 HIVE as the time of writing) but you can delegate at more accounts

This slipped past my re-read sorry, it's the opposite: you can delegate all your RC minus the account creation fee

Oh, ok! Thx

I think this will dramatically change the way I run the @podping system.

Instead of delegating Hive Power I'll be able to keep the active accounts topped up with RCs directly. Much better.

You can delegate to as many accounts as you want.
You can delegate to 100 accounts at once.

These two appear to contradict each other. Can you clarify? Do you mean you can delegate RC to 100 accounts in one operation but can delegate to an infinite amount of accounts overall?

You can't delegate more than the RC equivalent of the account creation fee (3 HIVE as the time of writing).

I believe the "more" should be changed to "less", right?

I think what he's saying is you can't delegate so much that it would eat into your "free" RC (account creation fee).

Yes, the wording could have been clearer, what I mean is that you can delegate to 100 accounts in a single operation

I believe the "more" should be changed to "less", right?

yep, thanks for catching that !

Bob is out of RC, Alice has 200 RC, so she uses her posting key to delegate 100 RC ...

Did I read posting key correctly? Does it mean that any account having posting authority on another account, which is quite frequent, could drain its RC?

You can delegate to 100 accounts at once.

Does it mean up to 100 or is 100 a random number provided as an example?

Did I read posting key correctly? Does it mean that any account having posting authority on another account, which is quite frequent, could drain its RC?

Yes, although not all of it. We went back and forth with this (active vs posting) and in the end we felt that it was more important to enable all the L2 solutions like RC trailing, RC pools etc than to lock it because it requires active.

Realistically there's much worse things that can be done with posting authority than just delegating RC away (downvoting everyone / posting spam everywhere that can't be deleted etc etc). And those don't happen even though the risk has always been there, so we felt like it's an okay tradeoff.

Worst comes to worst, RC is non-consensus so we can change this without a hard fork.

You can delegate to 100 accounts at once.

What I mean is you can delegate up to 100 accounts in a single op.

True but then is a "block RC" needed? If someone doesn't want it or wants it all back he must be able to opt-out.

Like allow RC delegation = No :) with active key.

I could imagine if RCs get Delegated to 10k wallets or more, it could be massive pain to get it back, so cancel all delegations would be helpful too IMO :)

Does delegating RC affect the amount of an accounts vote value? EX: 23K in RC and vote value of 0.40 If RC is now 13K for the account is the vote value unchanged?

Vote value isn't affected on either account.

Bear in mind that if you delegate too much RC you might not be able to use all your votes.

Thank you, even after 5 years I am still learning.

If I understood things correctly, the delegator keeps the voting power intact (because the HP is not delegated, only max RC).

Yes

Thank you, I think I understand now.

Yes, someone asked my question! Thank you. :) And how cool is it that my dust vote on the comment now counts?

Hmmmmmmm,

So 100% delegations means 100%- Basic RC ( like a wallet with no hive has) right?

That's cool.

Not the important. WEN :D

I remember "its possible to implement without HF" :D

So next HF? :)

It is possible to make changes to the RC code without a hard fork, but not without glitches because if not all nodes update (and they won't w/o a hard fork), they'll have different ideas of how much RC each account has. Some will allow and some will block the same transaction.

sure building some foundation first makes sense. Some standard :D

So 100% delegations means 100%- Basic RC ( like a wallet with no hive has) right?

Yep

WEN

It's going to ship with hard fork 26 so in a couple of weeks :)

sounds super nice!

Is there a website for Resurce Credits (RC) delegations? I mean for the operations. For example people could ask for (or fill) RC delegations. This would be very helpful/useful for new users. I currently have 2094 million RC. I would gladly help new users.

Nothing exists yet (the feature isn't live), but it could definitely be created :)

That I would like to know about!
🤓😎🤓

Thank You,
Looks Great - and You got my vote on the proposal!
Have an Amazing Sunday,
And Thanks Again!

Thank you !

Absolutely!
Have an Awesome Tuesday as Well!
I have a question...
As "Hive Stats" has been off for a good month now...
Do you know any stay trackers that are working now - not "Hive Tasks", also not working?
And account monitary tracker like the also recently stopped working "nuthman.com"?
Thanks if You know anything and again have a Great Week!

Hive is absolutely one of the best platforms in our time but this mathematics of #rc delegation looks very simple to apply but kind of complicated to understand so I chose not to delegate till I understand better.

This post answered all the questions that I had about RC delegation. Thanks!

That's the goal, glad I helped :D


~~~ embed:1559229581906911241 twitter metadata:Q2xvdWRzeXN0ZW04M3x8aHR0cHM6Ly90d2l0dGVyLmNvbS9DbG91ZHN5c3RlbTgzL3N0YXR1cy8xNTU5MjI5NTgxOTA2OTExMjQxfA== ~~~

The rewards earned on this comment will go directly to the people( @yeckingo1, @claudio83, @arc7icwolf ) sharing the post on Twitter as long as they are registered with @poshtoken. Sign up at https://hiveposh.com.

@littlebee4 This is the one we talk about i think you might be interested to know this info.
@hopestylist @olawalium you guys should check this out in the future we can help our new friends in Hive which is amazing.

Yep, this is exactly what I meant. Thanks for making me aware of this post. Will bookmark it.
I for sure will help out others in the future 🤓

Thank you so much for this.

Thanks for sharing. Very informative

Gracias ☺️ amigo por tu voto. Tu apoyo nos motiva en esta bella comunidad.

Thank you @howo for upvoting my Elden Ring post! Greatly appreciated :)

Dear, @howo

May we ask you to review and support our @cryptobrewmaster GameFi proposal on DHF? It can be found here

If you havent tried playing CryptoBrewMaster you can give it a shot. Our @hivefest presentation available here on the YouTube with a pitchdeck of what we building in general

Vote with Peakd.com, Ecency.com, Hivesigner

Thank you!

You delegate max RC and RC, so you can't do a delegation when you are out of RC.
When undelegating, the delegator only gets his max RC back, all unspent RC is burned. The delegator will regenerate the RC over time.

So with those 2 rules in mind i assume there also won't be a cooldown period when undelegating like HP has?