grin/core/src/consensus.rs

59 lines
2.7 KiB
Rust
Raw Normal View History

2016-11-11 03:02:47 +03:00
// Copyright 2016 The Grin Developers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! All the rules required for a cryptocurrency to have reach consensus across
//! the whole network are complex and hard to completely isolate. Some can be
//! simple parameters (like block reward), others complex algorithms (like
//! Merkle sum trees or reorg rules). However, as long as they're simple
2016-11-14 22:21:18 +03:00
//! enough, consensus-relevant constants and short functions should be kept
2016-11-11 03:02:47 +03:00
//! here.
/// The block subsidy amount
pub const REWARD: u64 = 1_000_000_000;
2016-11-11 04:19:03 +03:00
/// Block interval, in seconds, the network will tune its difficulty for. Note
/// that contrarily to bitcoin, we may reduce this value in the future as
/// networks improve and block propagation is optimized (adjusting the reward
/// accordingly).
pub const BLOCK_TIME_SEC: u8 = 30;
2016-11-11 03:02:47 +03:00
/// Cuckoo-cycle proof size (cycle length)
pub const PROOFSIZE: usize = 42;
2016-11-11 04:19:03 +03:00
/// Default Cuckoo Cycle size shift used is 28. We may decide to increase it
/// when hashrate increases. May also start lower.
2016-11-11 03:02:47 +03:00
pub const SIZESHIFT: u32 = 28;
/// Default Cuckoo Cycle easiness, high enough to have good likeliness to find
/// a solution.
pub const EASINESS: u32 = 50;
2016-11-11 04:19:03 +03:00
/// Default number of blocks in the past when cross-block cut-through will start
/// happening. Needs to be long enough to not overlap with a long reorg. Rational
/// behind the value is the longest bitcoin fork was about 30 blocks, so 5h. We
/// add an order of magnitude to be safe and round to 48h of blocks to make it
/// easier to reason about.
pub const CUT_THROUGH_HORIZON: u32 = 48 * 3600 / (BLOCK_TIME_SEC as u32);
2016-11-11 03:02:47 +03:00
/// Max target hash, lowest difficulty
pub const MAX_TARGET: [u32; PROOFSIZE] =
[0xfff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff];
/// The maximum number of inputs or outputs a transaction may have
/// and be deserializable. Only for DoS protection.
pub const MAX_IN_OUT_LEN: u64 = 50000;