Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
1e9cfef
feat: accurate CheckError expressions in ReadOnlyChecker, enable `-` …
Sep 30, 2020
a384fc2
first pass on pox pooling/delegation
Sep 30, 2020
7ea2898
add contract-caller allowances to stack-stx, update boot::tests with …
Sep 30, 2020
1ba4efc
add delegation unit tests, some fixes, support in the special cc handler
Oct 1, 2020
2f1694c
fix min threshold constant for testnet
Oct 2, 2020
3a69a8d
test: fix delegation test case
Oct 2, 2020
8477e6c
threshold scaling + reward address repeating
Oct 5, 2020
773cc34
Merge remote-tracking branch 'origin/next' into feat/pox-delegation
Oct 6, 2020
c833b65
update stack-aggregation-commit comment
Oct 6, 2020
103c3d9
Merge remote-tracking branch 'origin/next' into feat/pox-thresholds
Oct 6, 2020
8f35d5a
#ignore test flake
Oct 6, 2020
d4aaa15
unit+int tests for threshold/addr repeats. write burnchain config to …
Oct 6, 2020
49605a7
don't remove expired entries
Oct 6, 2020
d05980e
sum stacked amounts across multiple entries from same address + int a…
Oct 6, 2020
196a280
threshold scaling + reward address repeating
Oct 5, 2020
6d81a5e
unit+int tests for threshold/addr repeats. write burnchain config to …
Oct 6, 2020
98f42a8
sum stacked amounts across multiple entries from same address + int a…
Oct 6, 2020
d4101c0
Merge branch 'feat/pox-thresholds' of github.com:blockstack/stacks-bl…
Oct 6, 2020
3c4aa04
delegator -> delegate
Oct 7, 2020
ef6012a
Merge branch 'feat/pox-delegation' into feat/pox-thresholds
Oct 7, 2020
1ad5c60
docs: add docsgen for boot contract
Oct 7, 2020
4745049
use more detailed error types
Oct 7, 2020
f8c2992
Merge pull request #1937 from blockstack/feat/pox-delegation
Oct 7, 2020
7b1bdae
Merge remote-tracking branch 'origin/next' into feat/pox-thresholds
Oct 7, 2020
80d9657
Merge branch 'feat/pox-thresholds' into feat/boot-code-docs
Oct 7, 2020
5cb5b9e
cargo fmt
Oct 7, 2020
106f80a
Merge branch 'feat/pox-thresholds' into feat/boot-code-docs
Oct 7, 2020
d8e5c8f
docs: autogeneration for boot contracts, add boot-contracts-reference…
Oct 8, 2020
e45de8a
Merge branch 'master' into next
Oct 8, 2020
f599d0d
Merge branch 'next' into feat/pox-thresholds
Oct 8, 2020
0328cbd
Merge branch 'feat/pox-thresholds' into feat/boot-code-docs
Oct 8, 2020
4ebed59
oops, need an import
Oct 8, 2020
185d4d4
add burn-block-ht recency constraints, update existing tests
Oct 8, 2020
6772aab
add some docs+comments for threshold scaling consts and calculations
Oct 9, 2020
5091378
Merge branch 'feat/pox-thresholds' into feat/recency
Oct 9, 2020
eed4dda
add integration and unit tests for the participation threshold
Oct 9, 2020
33ec31b
use config option to control sample size, hardcode sample wait
Oct 13, 2020
f8753cd
Merge pull request #1954 from blockstack/feat/pox-thresholds
Oct 13, 2020
5a88fe8
add arg to PoxConstants::new
Oct 13, 2020
cce60cd
Merge pull request #1961 from blockstack/feat/recency
Oct 13, 2020
1528941
Merge pull request #1957 from blockstack/feat/boot-code-docs
Oct 13, 2020
ad32bd5
Merge remote-tracking branch 'origin/master' into next
Oct 13, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/actions/docsgen/Dockerfile.docsgen
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ WORKDIR /src

COPY . .

RUN apt-get update && apt-get install -y git
RUN apt-get update && apt-get install -y git jq

RUN cargo build

RUN mkdir /out

RUN /src/target/debug/blockstack-core docgen > /out/clarity-reference.json
RUN /src/target/debug/blockstack-core docgen | jq . > /out/clarity-reference.json
RUN /src/target/debug/blockstack-core docgen_boot | jq . > /out/boot-contracts-reference.json

FROM scratch AS export-stage
COPY --from=build /out/clarity-reference.json /
COPY --from=build /out/boot-contracts-reference.json /
12 changes: 7 additions & 5 deletions .github/workflows/docs-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,20 @@ jobs:
id: push
run: |
cd docs.blockstack
git config user.email "robots@robots.actions"
git config user.email "kantai+robot@gmail.com"
git config user.name "PR Robot"
git fetch --unshallow
git checkout -b $ROBOT_BRANCH
cp ../docs-output/clarity-reference.json ./src/_data/clarity-reference.json
if $(git diff --quiet --exit-code); then
echo "No clarity-reference.json changes, stopping"
cp ../docs-output/boot-contracts-reference.json ./src/_data/boot-contracts-reference.json
git add src/_data/clarity-reference.json
git add src/_data/boot-contracts-reference.json
if $(git diff --staged --quiet --exit-code); then
echo "No reference.json changes, stopping"
echo "::set-output name=open_pr::0"
else
git remote add robot https://github.com/$ROBOT_OWNER/$ROBOT_REPO
git add src/_data/clarity-reference.json
git commit -m "auto: update clarity-reference.json from stacks-blockchain@${GITHUB_SHA}"
git commit -m "auto: update Clarity references JSONs from stacks-blockchain@${GITHUB_SHA}"
git push robot $ROBOT_BRANCH
echo "::set-output name=open_pr::1"
fi
Expand Down
25 changes: 22 additions & 3 deletions src/burnchains/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ pub struct PoxConstants {
/// fraction of liquid STX that must vote to reject PoX for
/// it to revert to PoB in the next reward cycle
pub pox_rejection_fraction: u64,
/// percentage of liquid STX that must participate for PoX
/// to occur
pub pox_participation_threshold_pct: u64,
_shadow: PhantomData<()>,
}

Expand All @@ -289,6 +292,7 @@ impl PoxConstants {
prepare_length: u32,
anchor_threshold: u32,
pox_rejection_fraction: u64,
pox_participation_threshold_pct: u64,
) -> PoxConstants {
assert!(anchor_threshold > (prepare_length / 2));

Expand All @@ -297,20 +301,35 @@ impl PoxConstants {
prepare_length,
anchor_threshold,
pox_rejection_fraction,
pox_participation_threshold_pct,
_shadow: PhantomData,
}
}
#[cfg(test)]
pub fn test_default() -> PoxConstants {
PoxConstants::new(10, 5, 3, 25)
PoxConstants::new(10, 5, 3, 25, 5)
}

pub fn reward_slots(&self) -> u32 {
self.reward_cycle_length
}

/// is participating_ustx enough to engage in PoX in the next reward cycle?
pub fn enough_participation(&self, participating_ustx: u128, liquid_ustx: u128) -> bool {
participating_ustx
.checked_mul(100)
.expect("OVERFLOW: uSTX overflowed u128")
> liquid_ustx
.checked_mul(self.pox_participation_threshold_pct as u128)
.expect("OVERFLOW: uSTX overflowed u128")
}

pub fn mainnet_default() -> PoxConstants {
PoxConstants::new(1000, 240, 192, 25)
PoxConstants::new(1000, 240, 192, 25, 5)
}

pub fn testnet_default() -> PoxConstants {
PoxConstants::new(120, 30, 20, 3333333333333333) // total liquid supply is 40000000000000000 µSTX
PoxConstants::new(120, 30, 20, 3333333333333333, 5) // total liquid supply is 40000000000000000 µSTX
}
}

Expand Down
67 changes: 61 additions & 6 deletions src/chainstate/coordinator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

use std::collections::VecDeque;
use std::convert::TryInto;
use std::convert::{TryFrom, TryInto};
use std::time::Duration;

use burnchains::{
Expand All @@ -28,13 +28,18 @@ use chainstate::burn::{
BlockHeaderHash, BlockSnapshot, ConsensusHash,
};
use chainstate::stacks::{
boot::STACKS_BOOT_CODE_CONTRACT_ADDRESS,
db::{ClarityTx, StacksChainState, StacksHeaderInfo},
events::StacksTransactionReceipt,
Error as ChainstateError, StacksAddress, StacksBlock, StacksBlockHeader, StacksBlockId,
};
use monitoring::increment_stx_blocks_processed_counter;
use util::db::Error as DBError;
use vm::{costs::ExecutionCost, types::PrincipalData};
use vm::{
costs::ExecutionCost,
types::{PrincipalData, QualifiedContractIdentifier},
Value,
};

pub mod comm;
use chainstate::stacks::index::MarfTrieId;
Expand Down Expand Up @@ -177,10 +182,35 @@ impl RewardSetProvider for OnChainRewardSetProvider {
sortdb: &SortitionDB,
block_id: &StacksBlockId,
) -> Result<Vec<StacksAddress>, Error> {
let res =
let registered_addrs =
chainstate.get_reward_addresses(burnchain, sortdb, current_burn_height, block_id)?;
let addresses = res.iter().map(|a| a.0).collect::<Vec<StacksAddress>>();
Ok(addresses)

let liquid_ustx = StacksChainState::get_stacks_block_header_info_by_index_block_hash(
chainstate.headers_db(),
block_id,
)?
.expect("CORRUPTION: Failed to look up block header info for PoX anchor block")
.total_liquid_ustx;

let (threshold, participation) = StacksChainState::get_reward_threshold_and_participation(
&burnchain.pox_constants,
&registered_addrs,
liquid_ustx,
);

if !burnchain
.pox_constants
.enough_participation(participation, liquid_ustx)
{
info!("PoX reward cycle did not have enough participation. Defaulting to burn. participation={}, liquid_ustx={}, burn_height={}",
participation, liquid_ustx, current_burn_height);
return Ok(vec![]);
}

Ok(StacksChainState::make_reward_set(
threshold,
registered_addrs,
))
}
}

Expand Down Expand Up @@ -212,7 +242,32 @@ impl<'a, T: BlockEventDispatcher>
stacks_chain_id,
chain_state_path,
initial_balances,
boot_block_exec,
|clarity_tx| {
let burnchain = burnchain.clone();
let contract = QualifiedContractIdentifier::parse(&format!(
"{}.pox",
STACKS_BOOT_CODE_CONTRACT_ADDRESS
))
.expect("Failed to construct boot code contract address");
let sender = PrincipalData::from(contract.clone());

clarity_tx.connection().as_transaction(|conn| {
conn.run_contract_call(
&sender,
&contract,
"set-burnchain-parameters",
&[
Value::UInt(burnchain.first_block_height as u128),
Value::UInt(burnchain.pox_constants.prepare_length as u128),
Value::UInt(burnchain.pox_constants.reward_cycle_length as u128),
Value::UInt(burnchain.pox_constants.pox_rejection_fraction as u128),
],
|_, _| false,
)
.expect("Failed to set burnchain parameters in PoX contract");
});
boot_block_exec(clarity_tx)
},
block_limit,
)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/chainstate/coordinator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ fn make_reward_set_coordinator<'a>(

pub fn get_burnchain(path: &str) -> Burnchain {
let mut b = Burnchain::new(&format!("{}/burnchain/db/", path), "bitcoin", "regtest").unwrap();
b.pox_constants = PoxConstants::new(5, 3, 3, 25);
b.pox_constants = PoxConstants::new(5, 3, 3, 25, 5);
b
}

Expand Down
Loading