Skip to content

Dynamic validator module outline #1536

Closed

Description

@foriequal0

Actions

Action::TransferCCS {},
Action::DelegateCCS {},

Action::Revoke {
    delegatee: Address,
    quantity: u64, // CCS
},
Action::SelfNomination {
    deposit: u64, // CCC
    metadata: Bytes
}
Action::ReportDoubleVote {
    header1: Header,
    sig1: H256,
    header2: Header,
    sig2: H256,
}

States

Existing

stakeholders = [ address+ ]
balance(address) = quantity
delegation(delegator) = [ [delegatee, quantity]+ ]

New states

candidates = [ [address, deposits, nominate_end_at]+ ], address asc
pending_rewards = [ [withdraw_at, address, quantity]+ ], [withdraw_at, address] asc
banned = [ address+ ], address asc
jailed = [ [address, deposits, custody_until, kicked_at]+ ], address asc

Action handlers

handle_self_nomination(deposit):
  if sender in banned:
    error
  if sender in jailed:
    if current_term < custody_until:
      error
    else:
      jailed.reomve(sender)
  candidates.update(sender, deposit, current_term + NOMINATE_EXPIRATION)
  sender.subtract(deposit)

handle_transfer(): ...

handle_delegate(delegatee, quantity):
  if sender in banned:
    error
  if sender not in candidates or jailed:
    error
  delegation(sender).add(delegatee, quantity)

handle_revoke():
  delegation(sender).subtract(delegatee, quantity)

handle_double_sign(header1, sig1, header2, sig2):
  if !check_sig(header1, sig1) || !check_sig(header2, sig2):
    error
  pending_rewards.remove(address)
  candidates.remove(address)
  revert_delegation(address)
  validators.remove(address)
  validator_order.remove(address)
  jail.remove(address)
  banned.push(address)

other events

jail(address):
  deposit = candidates.remove(address)
  validators.remove(address)
  validator_order.remove(address)
  jailed.add(address, deposit
    current_term + CUSTODY_PERIOD, 
    current_term + RELEASE_PERIOD)
  
on_block_close():
  pending_rewards.update([current_term + WITHDRAW_DELAY, address], express_fee)

on_term_close():
  total_slash = slash_unresponsive(headers, pending_rewards)
  pending_rewards.update(signature_reward(blocks, total_slash))
  auto_expire_nominate(candidates, delegation)
  auto_withdraw(pending_rewards)
  kick(jailed)
  validators, validator_order = elect()

Activity

  1. self-assigned this
    on May 15, 2019
  2. foriequal0 commented on May 20, 2019

    @foriequal0
    ContributorAuthor

    @sgkim126 how about merging deposits and candidates? I think they have overlapped lifetimes.

    --- dynamic-validator.a.md
    +++ dynamic-validator.b.md
    @@ -28,9 +28,8 @@
     ### New states
    
    -deposits = [ [address, deposit]+ ], address asc
    -candidates = [ [address, nominate_end_at]+ ], address asc
    +candidates = [ [address, deposits, nominate_end_at]+ ], address asc
     pending_rewards = [ [withdraw_at, address, quantity]+ ], [withdraw_at, address] asc
     banned = [ address+ ], address asc
    -jailed = [ [address, custody_until, kicked_at]+ ], address asc
    +jailed = [ [address, deposits, custody_until, kicked_at]+ ], address asc
    
     ### COL_EXTRA
    @@ -51,6 +50,5 @@
         else:
           jailed.remove(sender)
    -  deposits.update(sender, deposit)
    -  candidates.update(sender, current_term + NOMINATE_EXPIRATION)
    +  candidates.update(sender, deposit, current_term + NOMINATE_EXPIRATION)
       sender.subtract(deposit)
    
    @@ -69,5 +67,4 @@
         error
       pending_rewards.remove(address)
    -  deposits.remove(address)
       candidates.remove(address)
       revert_delegation(address)
    @@ -80,8 +77,8 @@
    
     jail(address):
    -  candidates.remove(address)
    +  deposit = candidates.remove(address)
       validators.remove(address)
       validator_order.remove(address)
    -  jailed.add(address,
    +  jailed.add(address, deposit
         current_term + CUSTODY_PERIOD,
         current_term + RELEASE_PERIOD)
    @@ -93,7 +90,7 @@
       total_slash = slash_unresponsive(headers, pending_rewards)
       pending_rewards.update(signature_reward(blocks, total_slash))
    -  auto_expire_nominate(candidates, deposits, delegation)
    +  auto_expire_nominate(candidates, delegation)
       auto_withdraw(pending_rewards)
    -  kick(jailed, deposits)
    +  kick(jailed)
       validators, validator_order = elect()
    
  3. sgkim126 commented on May 20, 2019

    @sgkim126
    Contributor
  4. sgkim126 commented on May 21, 2019

    @sgkim126
    Contributor

    @foriequal0 How about storing the validators sets in the states?
    It would simplify the restoring logic.

  5. foriequal0 commented on May 22, 2019

    @foriequal0
    ContributorAuthor

    I've applied the diff. Data saved in COL_EXTRA like the validator set and the validator order is not stored anymore. It should be recovered from the last term end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions