mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-04 08:44:28 +00:00
sharding: abi name changes fixed other packages
Former-commit-id: eeb039b0e54b958cd64174495c8632ca66e240d1 [formerly dc0fb2653ee915b4033d3ed8cca10a4204ae7de8] Former-commit-id: b138547efd51ac985ff7c759eea5d288149b460a
This commit is contained in:
parent
b923b9e101
commit
08325ed7d4
@ -56,21 +56,22 @@ func subscribeBlockHeaders(c client.Client) error {
|
|||||||
// conditions are met
|
// conditions are met
|
||||||
func checkSMCForCollator(c client.Client, head *types.Header) error {
|
func checkSMCForCollator(c client.Client, head *types.Header) error {
|
||||||
log.Info("Checking if we are an eligible collation collator for a shard...")
|
log.Info("Checking if we are an eligible collation collator for a shard...")
|
||||||
period := big.NewInt(0).Div(head.Number, big.NewInt(sharding.PeriodLength))
|
|
||||||
for s := int64(0); s < sharding.ShardCount; s++ {
|
for s := int64(0); s < sharding.ShardCount; s++ {
|
||||||
// Checks if we are an eligible collator according to the SMC
|
// Checks if we are an eligible collator according to the SMC
|
||||||
addr, err := c.SMCCaller().GetEligibleCollator(&bind.CallOpts{}, big.NewInt(s), period)
|
for i := int64(0); i < sharding.NotaryCommitSize; s++ {
|
||||||
|
addr, err := c.SMCCaller().GetNotaryInCommittee(&bind.CallOpts{}, big.NewInt(s), i)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// If output is non-empty and the addr == coinbase
|
|
||||||
if addr == c.Account().Address {
|
|
||||||
log.Info(fmt.Sprintf("Selected as collator on shard: %d", s))
|
|
||||||
err := submitCollation(s)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not add collation. %v", err)
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// If output is non-empty and the addr == coinbase
|
||||||
|
if addr == c.Account().Address {
|
||||||
|
log.Info(fmt.Sprintf("Selected as collator on shard: %d", s))
|
||||||
|
err := submitCollation(s)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not add collation. %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -85,11 +86,11 @@ func checkSMCForCollator(c client.Client, head *types.Header) error {
|
|||||||
func isAccountInCollatorPool(c client.Client) (bool, error) {
|
func isAccountInCollatorPool(c client.Client) (bool, error) {
|
||||||
account := c.Account()
|
account := c.Account()
|
||||||
// Checks if our deposit has gone through according to the SMC
|
// Checks if our deposit has gone through according to the SMC
|
||||||
b, err := c.SMCCaller().IsCollatorDeposited(&bind.CallOpts{}, account.Address)
|
b, err := c.SMCCaller().NotaryRegistry(&bind.CallOpts{}, account.Address)
|
||||||
if !b && err != nil {
|
if !b.Deposited && err != nil {
|
||||||
log.Warn(fmt.Sprintf("Account %s not in collator pool.", account.Address.String()))
|
log.Warn(fmt.Sprintf("Account %s not in collator pool.", account.Address.String()))
|
||||||
}
|
}
|
||||||
return b, err
|
return b.Deposited, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// submitCollation interacts with the SMC directly to add a collation header
|
// submitCollation interacts with the SMC directly to add a collation header
|
||||||
@ -132,7 +133,7 @@ func joinCollatorPool(c client.Client) error {
|
|||||||
return fmt.Errorf("unable to intiate the deposit transaction: %v", err)
|
return fmt.Errorf("unable to intiate the deposit transaction: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tx, err := c.SMCTransactor().Deposit(txOps)
|
tx, err := c.SMCTransactor().RegisterNotary(txOps)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to deposit eth and become a collator: %v", err)
|
return fmt.Errorf("unable to deposit eth and become a collator: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ func TestIsAccountInCollatorPool(t *testing.T) {
|
|||||||
txOpts := transactOpts()
|
txOpts := transactOpts()
|
||||||
// deposit in collator pool, then it should return true
|
// deposit in collator pool, then it should return true
|
||||||
txOpts.Value = sharding.NotaryDeposit
|
txOpts.Value = sharding.NotaryDeposit
|
||||||
if _, err := smc.Deposit(txOpts); err != nil {
|
if _, err := smc.RegisterNotary(txOpts); err != nil {
|
||||||
t.Fatalf("Failed to deposit: %v", err)
|
t.Fatalf("Failed to deposit: %v", err)
|
||||||
}
|
}
|
||||||
backend.Commit()
|
backend.Commit()
|
||||||
@ -105,7 +105,7 @@ func TestJoinCollatorPool(t *testing.T) {
|
|||||||
client := &mockClient{smc, t}
|
client := &mockClient{smc, t}
|
||||||
|
|
||||||
// There should be no collators initially
|
// There should be no collators initially
|
||||||
numCollators, err := smc.NumCollators(&bind.CallOpts{})
|
numCollators, err := smc.NotaryPoolLength(&bind.CallOpts{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -120,7 +120,7 @@ func TestJoinCollatorPool(t *testing.T) {
|
|||||||
backend.Commit()
|
backend.Commit()
|
||||||
|
|
||||||
// Now there should be one collator
|
// Now there should be one collator
|
||||||
numCollators, err = smc.NumCollators(&bind.CallOpts{})
|
numCollators, err = smc.NotaryPoolLength(&bind.CallOpts{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user