Merge pull request #86 from terenc3t/phase1-config

sharding: align config with phase 1 spec
Former-commit-id: 245fdf3b1c5a4373d85a15ed4209019550048b5f [formerly 5a1a835e491a7551c4a3d1a4614cc1f24e0e222a]
Former-commit-id: d5fcf87f42d798afa300f7bdba5b284414edb1dc
This commit is contained in:
Preston Van Loon
2018-04-02 21:52:52 -04:00
committed by GitHub
7 changed files with 61 additions and 19 deletions

View File

@@ -127,7 +127,7 @@ func submitCollation(shardID int64) error {
func joinCollatorPool(c client.Client) error {
log.Info("Joining collator pool")
txOps, err := c.CreateTXOps(sharding.DepositSize)
txOps, err := c.CreateTXOps(sharding.CollatorDeposit)
if err != nil {
return fmt.Errorf("unable to intiate the deposit transaction: %v", err)
}
@@ -136,7 +136,7 @@ func joinCollatorPool(c client.Client) error {
if err != nil {
return fmt.Errorf("unable to deposit eth and become a collator: %v", err)
}
log.Info(fmt.Sprintf("Deposited %dETH into contract with transaction hash: %s", new(big.Int).Div(sharding.DepositSize, big.NewInt(params.Ether)), tx.Hash().String()))
log.Info(fmt.Sprintf("Deposited %dETH into contract with transaction hash: %s", new(big.Int).Div(sharding.CollatorDeposit, big.NewInt(params.Ether)), tx.Hash().String()))
return nil
}

View File

@@ -17,7 +17,7 @@ import (
var (
key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
addr = crypto.PubkeyToAddress(key.PublicKey)
accountBalance1000Eth, _ = new(big.Int).SetString("1000000000000000000000", 10)
accountBalance1001Eth, _ = new(big.Int).SetString("1001000000000000000000", 10)
)
// Mock client for testing collator. Should this go into sharding/client/testing?
@@ -59,7 +59,7 @@ func (m *mockClient) Close() {
func TestIsAccountInCollatorPool(t *testing.T) {
// Test setup (should this go to sharding/client/testing?)
backend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: accountBalance1000Eth}})
backend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: accountBalance1001Eth}})
transactOpts := bind.NewKeyedTransactor(key)
_, _, smc, _ := contracts.DeploySMC(transactOpts, backend)
backend.Commit()
@@ -76,7 +76,7 @@ func TestIsAccountInCollatorPool(t *testing.T) {
}
// deposit in collator pool, then it should return true
transactOpts.Value = sharding.DepositSize
transactOpts.Value = sharding.CollatorDeposit
if _, err := smc.Deposit(transactOpts); err != nil {
t.Fatalf("Failed to deposit: %v", err)
}

View File

@@ -19,8 +19,20 @@ var (
PeriodLength = int64(5)
// Number of periods ahead of current period which the contract is able to return the collator of that period.
LookaheadPeriods = 4
// Required deposit size in wei
DepositSize = new(big.Int).Exp(big.NewInt(10), big.NewInt(20), nil) // 100 ETH
// Required deposit size in wei for collator
CollatorDeposit = new(big.Int).Exp(big.NewInt(10), big.NewInt(21), nil) // 1000 ETH
// Required deposit size in wei for proposer
ProposerDeposit = new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil) // 1 ETH
// Minimum Balance of proposer where bids are decuted
MinProposerBalance = new(big.Int).Exp(big.NewInt(10), big.NewInt(17), nil) // 0.1 ETH
// Gas limit to create contract
ContractGasLimit = uint64(4700000) // Max is 4712388
// Number of collations collators need to check to apply fork choice rule
WindbackLength = int64(25)
// Number of periods to lockup collator deposit from time of deregistration
CollatorLockupLength = int64(16128)
// Number of periods to lockup proposer deposit from time of deregistration
ProposerLockupLength = int64(48)
// Number of vETH awarded to collators after collation included in canonical chain
CollatorSubsidy = new(big.Int).Exp(big.NewInt(10), big.NewInt(15), nil) // 0.001 ETH
)

View File

@@ -5,12 +5,42 @@ import (
"testing"
)
func TestDepositSize(t *testing.T) {
want, err := new(big.Int).SetString("100000000000000000000", 10) // 100 ETH
func TestCollatorDeposit(t *testing.T) {
want, err := new(big.Int).SetString("1000000000000000000000", 10) // 1000 ETH
if !err {
t.Fatalf("Failed to setup test")
}
if DepositSize.Cmp(want) != 0 {
t.Errorf("depositSize incorrect. Wanted %d, got %d", want, DepositSize)
if CollatorDeposit.Cmp(want) != 0 {
t.Errorf("Collator deposit size incorrect. Wanted %d, got %d", want, CollatorDeposit)
}
}
func TestProposerDeposit(t *testing.T) {
want, err := new(big.Int).SetString("1000000000000000000", 10) // 1 ETH
if !err {
t.Fatalf("Failed to setup test")
}
if ProposerDeposit.Cmp(want) != 0 {
t.Errorf("Proposer deposit size incorrect. Wanted %d, got %d", want, ProposerDeposit)
}
}
func TestMinProposerBalance(t *testing.T) {
want, err := new(big.Int).SetString("100000000000000000", 10) // 0.1 ETH
if !err {
t.Fatalf("Failed to setup test")
}
if MinProposerBalance.Cmp(want) != 0 {
t.Errorf("Min proposer balance incorrect. Wanted %d, got %d", want, MinProposerBalance)
}
}
func TestCollatorSubsidy(t *testing.T) {
want, err := new(big.Int).SetString("1000000000000000", 10) // 0.001 ETH
if !err {
t.Fatalf("Failed to setup test")
}
if CollatorSubsidy.Cmp(want) != 0 {
t.Errorf("Collator subsidy size incorrect. Wanted %d, got %d", want, CollatorSubsidy)
}
}

File diff suppressed because one or more lines are too long

View File

@@ -64,7 +64,7 @@ contract SMC {
uint constant periodLength = 5;
int constant public shardCount = 100;
// The exact deposit size which you have to deposit to become a collator
uint constant depositSize = 100 ether;
uint constant depositSize = 1000 ether;
// Number of periods ahead of current period, which the contract
// is able to return the collator of that period
uint constant lookAheadPeriods = 4;

View File

@@ -15,8 +15,8 @@ import (
var (
key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
addr = crypto.PubkeyToAddress(key.PublicKey)
accountBalance1000Eth, _ = new(big.Int).SetString("1000000000000000000000", 10)
collatorDeposit, _ = new(big.Int).SetString("100000000000000000000", 10)
accountBalance1001Eth, _ = new(big.Int).SetString("1001000000000000000000", 10)
collatorDeposit, _ = new(big.Int).SetString("1000000000000000000000", 10)
)
func deploySMCContract(backend *backends.SimulatedBackend) (common.Address, *types.Transaction, *SMC, error) {
@@ -27,7 +27,7 @@ func deploySMCContract(backend *backends.SimulatedBackend) (common.Address, *typ
// Test creating the SMC contract
func TestContractCreation(t *testing.T) {
backend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: accountBalance1000Eth}})
backend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: accountBalance1001Eth}})
_, _, _, err := deploySMCContract(backend)
backend.Commit()
if err != nil {
@@ -37,7 +37,7 @@ func TestContractCreation(t *testing.T) {
// Test getting the collation gas limit
func TestGetCollationGasLimit(t *testing.T) {
backend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: accountBalance1000Eth}})
backend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: accountBalance1001Eth}})
_, _, smc, _ := deploySMCContract(backend)
gasLimit, err := smc.GetCollationGasLimit(&bind.CallOpts{})
if err != nil {
@@ -50,7 +50,7 @@ func TestGetCollationGasLimit(t *testing.T) {
// Test collator deposit
func TestCollatorDeposit(t *testing.T) {
backend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: accountBalance1000Eth}})
backend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: accountBalance1001Eth}})
transactOpts := bind.NewKeyedTransactor(key)
_, _, smc, _ := deploySMCContract(backend)
@@ -102,7 +102,7 @@ func TestCollatorDeposit(t *testing.T) {
// Test collator withdraw
func TestCollatorWithdraw(t *testing.T) {
backend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: accountBalance1000Eth}})
backend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: accountBalance1001Eth}})
transactOpts := bind.NewKeyedTransactor(key)
_, _, smc, _ := deploySMCContract(backend)