Skip to content

Commit

Permalink
Merge pull request #41 from ironbeer/fix-validator-schedule
Browse files Browse the repository at this point in the history
Extend block difficulty
  • Loading branch information
ironbeer authored Sep 19, 2023
2 parents e955016 + 370e808 commit f43fa54
Show file tree
Hide file tree
Showing 12 changed files with 685 additions and 534 deletions.
3 changes: 3 additions & 0 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ type ChainHeaderReader interface {

// GetTd retrieves the total difficulty from the database by hash and number.
GetTd(hash common.Hash, number uint64) *big.Int

// GetCanonicalHash returns the canonical hash for a given block number
GetCanonicalHash(number uint64) common.Hash
}

// ChainReader defines a small collection of methods needed to access the local
Expand Down
9 changes: 5 additions & 4 deletions consensus/oasys/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ func (c *Oasys) IsSystemTransaction(tx *types.Transaction, header *types.Header)
return false, nil
} else if _, ok := methods[called.RawName]; ok {
log.Info("System method transacted",
"validator", header.Coinbase.Hex(), "tx", tx.Hash().Hex(),
"number", header.Number, "hash", header.Hash().Hex(),
"tx", tx.Hash().Hex(), "validator", header.Coinbase.Hex(),
"contract", contract.address.Hex(), "method", called.RawName)
return true, nil
}
Expand Down Expand Up @@ -332,7 +333,7 @@ func (c *Oasys) initializeSystemContracts(
// Transact the `StakeManager.slash` method.
func (c *Oasys) slash(
validator common.Address,
schedule map[uint64]common.Address,
schedules []*common.Address,
state *state.StateDB,
header *types.Header,
cx core.ChainContext,
Expand All @@ -343,8 +344,8 @@ func (c *Oasys) slash(
mining bool,
) error {
blocks := int64(0)
for _, address := range schedule {
if address == validator {
for _, address := range schedules {
if *address == validator {
blocks++
}
}
Expand Down
2 changes: 1 addition & 1 deletion consensus/oasys/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestSlash(t *testing.T) {
}

validator := accounts[0].Address
schedule := map[uint64]common.Address{}
schedule := []*common.Address{}
header := &types.Header{
Number: big.NewInt(50),
Coinbase: accounts[0].Address,
Expand Down
Loading

0 comments on commit f43fa54

Please sign in to comment.