Skip to content

Commit

Permalink
Merge branch 'master' into aurelius-admin-branch
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischarlesharrison committed Sep 14, 2023
2 parents 6de30ab + e69ede9 commit 2eea6bb
Show file tree
Hide file tree
Showing 45 changed files with 2,728 additions and 514 deletions.
24 changes: 12 additions & 12 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -801,18 +801,18 @@ type callMsg struct {
electroneum.CallMsg
}

func (m callMsg) From() common.Address { return m.CallMsg.From }
func (m callMsg) Nonce() uint64 { return 0 }
func (m callMsg) IsFake() bool { return true }
func (m callMsg) To() *common.Address { return m.CallMsg.To }
func (m callMsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
func (m callMsg) GasFeeCap() *big.Int { return m.CallMsg.GasFeeCap }
func (m callMsg) GasTipCap() *big.Int { return m.CallMsg.GasTipCap }
func (m callMsg) PrioritySenderPubkey() common.PriorityPubkey { return m.CallMsg.PrioritySenderPubkey }
func (m callMsg) Gas() uint64 { return m.CallMsg.Gas }
func (m callMsg) Value() *big.Int { return m.CallMsg.Value }
func (m callMsg) Data() []byte { return m.CallMsg.Data }
func (m callMsg) AccessList() types.AccessList { return m.CallMsg.AccessList }
func (m callMsg) From() common.Address { return m.CallMsg.From }
func (m callMsg) Nonce() uint64 { return 0 }
func (m callMsg) IsFake() bool { return true }
func (m callMsg) To() *common.Address { return m.CallMsg.To }
func (m callMsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
func (m callMsg) GasFeeCap() *big.Int { return m.CallMsg.GasFeeCap }
func (m callMsg) GasTipCap() *big.Int { return m.CallMsg.GasTipCap }
func (m callMsg) PrioritySender() common.PublicKey { return m.CallMsg.PrioritySender }
func (m callMsg) Gas() uint64 { return m.CallMsg.Gas }
func (m callMsg) Value() *big.Int { return m.CallMsg.Value }
func (m callMsg) Data() []byte { return m.CallMsg.Data }
func (m callMsg) AccessList() types.AccessList { return m.CallMsg.AccessList }

// filterBackend implements filters.Backend to support filtering for logs without
// taking bloom-bits acceleration structures into account.
Expand Down
2 changes: 2 additions & 0 deletions cmd/etn-sc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ var (
utils.TxPoolPriceBumpFlag,
utils.TxPoolAccountSlotsFlag,
utils.TxPoolGlobalSlotsFlag,
utils.TxPoolPrioritySlotsFlag,
utils.TxPoolAccountQueueFlag,
utils.TxPoolGlobalQueueFlag,
utils.TxPoolPriorityQueueFlag,
utils.TxPoolLifetimeFlag,
utils.SyncModeFlag,
utils.ExitWhenSyncedFlag,
Expand Down
2 changes: 2 additions & 0 deletions cmd/etn-sc/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ var AppHelpFlagGroups = []flags.FlagGroup{
utils.TxPoolPriceBumpFlag,
utils.TxPoolAccountSlotsFlag,
utils.TxPoolGlobalSlotsFlag,
utils.TxPoolPrioritySlotsFlag,
utils.TxPoolAccountQueueFlag,
utils.TxPoolGlobalQueueFlag,
utils.TxPoolPriorityQueueFlag,
utils.TxPoolLifetimeFlag,
},
},
Expand Down
16 changes: 16 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@ var (
Usage: "Maximum number of executable transaction slots for all accounts",
Value: ethconfig.Defaults.TxPool.GlobalSlots,
}
TxPoolPrioritySlotsFlag = cli.Uint64Flag{
Name: "txpool.priorityslots",
Usage: "Minimum number of executable priority transaction slots guaranteed per account",
Value: ethconfig.Defaults.TxPool.PrioritySlots,
}
TxPoolAccountQueueFlag = cli.Uint64Flag{
Name: "txpool.accountqueue",
Usage: "Maximum number of non-executable transaction slots permitted per account",
Expand All @@ -383,6 +388,11 @@ var (
Usage: "Maximum number of non-executable transaction slots for all accounts",
Value: ethconfig.Defaults.TxPool.GlobalQueue,
}
TxPoolPriorityQueueFlag = cli.Uint64Flag{
Name: "txpool.priorityqueue",
Usage: "Maximum number of non-executable priority transaction slots for all accounts",
Value: ethconfig.Defaults.TxPool.PriorityQueue,
}
TxPoolLifetimeFlag = cli.DurationFlag{
Name: "txpool.lifetime",
Usage: "Maximum amount of time non-executable transaction are queued",
Expand Down Expand Up @@ -1401,12 +1411,18 @@ func setTxPool(ctx *cli.Context, cfg *core.TxPoolConfig) {
if ctx.GlobalIsSet(TxPoolGlobalSlotsFlag.Name) {
cfg.GlobalSlots = ctx.GlobalUint64(TxPoolGlobalSlotsFlag.Name)
}
if ctx.GlobalIsSet(TxPoolPrioritySlotsFlag.Name) {
cfg.PrioritySlots = ctx.GlobalUint64(TxPoolPrioritySlotsFlag.Name)
}
if ctx.GlobalIsSet(TxPoolAccountQueueFlag.Name) {
cfg.AccountQueue = ctx.GlobalUint64(TxPoolAccountQueueFlag.Name)
}
if ctx.GlobalIsSet(TxPoolGlobalQueueFlag.Name) {
cfg.GlobalQueue = ctx.GlobalUint64(TxPoolGlobalQueueFlag.Name)
}
if ctx.GlobalIsSet(TxPoolPriorityQueueFlag.Name) {
cfg.PriorityQueue = ctx.GlobalUint64(TxPoolPriorityQueueFlag.Name)
}
if ctx.GlobalIsSet(TxPoolLifetimeFlag.Name) {
cfg.Lifetime = ctx.GlobalDuration(TxPoolLifetimeFlag.Name)
}
Expand Down
108 changes: 54 additions & 54 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ const (
// HashLength is the expected length of the hash
HashLength = 32
// AddressLength is the expected length of the address
AddressLength = 20
PriorityPubkeyLength = 65
AddressLength = 20
PublicKeyLength = 65
)

var (
hashT = reflect.TypeOf(Hash{})
addressT = reflect.TypeOf(Address{})
priorityPubkeyT = reflect.TypeOf(PriorityPubkey{})
hashT = reflect.TypeOf(Hash{})
addressT = reflect.TypeOf(Address{})
PublicKeyT = reflect.TypeOf(PublicKey{})
)

// Hash represents the 32 byte Keccak256 hash of arbitrary data.
Expand Down Expand Up @@ -445,13 +445,13 @@ type PriorityTransactor struct {
EntityName string
}

// PriorityPubkey represents the 65 byte *uncompressed* secp256k1 pubkey used for priority signatures within txes of PriorityTx type
type PriorityPubkey [PriorityPubkeyLength]byte
// PublicKey represents the 65 byte *uncompressed* secp256k1 pubkey used for priority signatures within txes of PriorityTx type
type PublicKey [PublicKeyLength]byte

type PriorityTransactorMap map[PriorityPubkey]PriorityTransactor
type PriorityTransactorMap map[PublicKey]PriorityTransactor

// IsValid checks if the public key is a valid uncompressed secp256k1 public key and if it lies on the secp256k1 curve
func (p PriorityPubkey) IsValid() bool {
func (p PublicKey) IsValid() bool {
if p[0] != 4 {
// uncompressed public keys should start with 0x04
return false
Expand All @@ -462,62 +462,62 @@ func (p PriorityPubkey) IsValid() bool {
return secp256k1.S256().IsOnCurve(x, y)
}

// BytesToPriorityPubkey returns PriorityPubkey with value b.
// BytesToPublicKey returns PublicKey with value b.
// If b is larger than len(h), b will be cropped from the left.
func BytesToPriorityPubkey(b []byte) PriorityPubkey {
var p PriorityPubkey
func BytesToPublicKey(b []byte) PublicKey {
var p PublicKey
p.SetBytes(b)
return p
}

func StringToPriorityPubkey(s string) PriorityPubkey { return BytesToPriorityPubkey([]byte(s)) }
func StringToPublicKey(s string) PublicKey { return BytesToPublicKey([]byte(s)) }

// BigToPriorityPubkey returns PriorityPubkey with byte values of b.
// BigToPublicKey returns PublicKey with byte values of b.
// If b is larger than len(h), b will be cropped from the left.
func BigToPriorityPubkey(b *big.Int) PriorityPubkey { return BytesToPriorityPubkey(b.Bytes()) }
func BigToPublicKey(b *big.Int) PublicKey { return BytesToPublicKey(b.Bytes()) }

// HexToPriorityPubkey returns PriorityPubkey with byte values of s.
// HexToPublicKey returns PublicKey with byte values of s.
// If s is larger than len(h), s will be cropped from the left.
func HexToPriorityPubkey(s string) PriorityPubkey { return BytesToPriorityPubkey(FromHex(s)) }
func HexToPublicKey(s string) PublicKey { return BytesToPublicKey(FromHex(s)) }

// IsHexPriorityPubkey verifies whether a string can represent a valid hex-encoded
// secp256k1 PriorityPubkey or not.
func IsHexPriorityPubkey(s string) bool {
// IsHexPublicKey verifies whether a string can represent a valid hex-encoded
// secp256k1 PublicKey or not.
func IsHexPublicKey(s string) bool {
if has0xPrefix(s) {
s = s[2:]
}
return len(s) == 2*PriorityPubkeyLength && isHex(s)
return len(s) == 2*PublicKeyLength && isHex(s)
}

// Bytes gets the string representation of the underlying PriorityPubkey.
func (p PriorityPubkey) Bytes() []byte { return p[:] }
// Bytes gets the string representation of the underlying PublicKey.
func (p PublicKey) Bytes() []byte { return p[:] }

// Hash converts an PriorityPubkey to a hash by left-padding it with zeros.
func (p PriorityPubkey) Hash() Hash { return BytesToHash(p[:]) }
// Hash converts an PublicKey to a hash by left-padding it with zeros.
func (p PublicKey) Hash() Hash { return BytesToHash(p[:]) }

// String implements fmt.Stringer.
func (p PriorityPubkey) String() string {
func (p PublicKey) String() string {
return string(p.hex())
}

func (p PriorityPubkey) ToHexString() string {
func (p PublicKey) ToHexString() string {
return string(p.hex())
}

func (p PriorityPubkey) ToPaddedHexString() string {
func (p PublicKey) ToUnprefixedHexString() string {
return string(p.hex()[2:])
}

func (p PriorityPubkey) hex() []byte {
func (p PublicKey) hex() []byte {
var buf [len(p)*2 + 2]byte
copy(buf[:2], "0x")
hex.Encode(buf[2:], p[:])
return buf[:]
}

// Format implements fmt.Formatter.
// PriorityPubkey supports the %v, %s, %q, %x, %X and %d format verbs.
func (p PriorityPubkey) Format(s fmt.State, c rune) {
// PublicKey supports the %v, %s, %q, %x, %X and %d format verbs.
func (p PublicKey) Format(s fmt.State, c rune) {
switch c {
case 'v', 's', 'x', 'X':
hex := p.hex()
Expand All @@ -536,76 +536,76 @@ func (p PriorityPubkey) Format(s fmt.State, c rune) {
case 'd':
fmt.Fprint(s, ([len(p)]byte)(p))
default:
fmt.Fprintf(s, "%%!%c(PriorityPubkey=%x)", c, p)
fmt.Fprintf(s, "%%!%c(PublicKey=%x)", c, p)
}
}

// SetBytes sets the PriorityPubkey to the value of b.
// SetBytes sets the PublicKey to the value of b.
// If b is larger than len(a), b will be cropped from the left.
func (p *PriorityPubkey) SetBytes(b []byte) {
func (p *PublicKey) SetBytes(b []byte) {
if len(b) > len(p) {
b = b[len(b)-PriorityPubkeyLength:]
b = b[len(b)-PublicKeyLength:]
}
copy(p[PriorityPubkeyLength-len(b):], b)
copy(p[PublicKeyLength-len(b):], b)
}

// MarshalText returns the hex representation of a.
func (p PriorityPubkey) MarshalText() ([]byte, error) {
func (p PublicKey) MarshalText() ([]byte, error) {
return hexutil.Bytes(p[:]).MarshalText()
}

// UnmarshalText parses a hash in hex syntax.
func (p *PriorityPubkey) UnmarshalText(input []byte) error {
return hexutil.UnmarshalFixedText("PriorityPubkey", input, p[:])
func (p *PublicKey) UnmarshalText(input []byte) error {
return hexutil.UnmarshalFixedText("PublicKey", input, p[:])
}

// UnmarshalJSON parses a hash in hex syntax.
func (p *PriorityPubkey) UnmarshalJSON(input []byte) error {
return hexutil.UnmarshalFixedJSON(priorityPubkeyT, input, p[:])
func (p *PublicKey) UnmarshalJSON(input []byte) error {
return hexutil.UnmarshalFixedJSON(PublicKeyT, input, p[:])
}

// Scan implements Scanner for database/sql.
func (p *PriorityPubkey) Scan(src interface{}) error {
func (p *PublicKey) Scan(src interface{}) error {
srcB, ok := src.([]byte)
if !ok {
return fmt.Errorf("can't scan %T into PriorityPubkey", src)
return fmt.Errorf("can't scan %T into PublicKey", src)
}
if len(srcB) != PriorityPubkeyLength {
return fmt.Errorf("can't scan []byte of len %d into PriorityPubkey, want %d", len(srcB), PriorityPubkeyLength)
if len(srcB) != PublicKeyLength {
return fmt.Errorf("can't scan []byte of len %d into PublicKey, want %d", len(srcB), PublicKeyLength)
}
copy(p[:], srcB)
return nil
}

// Value implements valuer for database/sql.
func (p PriorityPubkey) Value() (driver.Value, error) {
func (p PublicKey) Value() (driver.Value, error) {
return p[:], nil
}

// ImplementsGraphQLType returns true if Hash implements the specified GraphQL type.
func (p PriorityPubkey) ImplementsGraphQLType(name string) bool { return name == "PriorityPubkey" }
func (p PublicKey) ImplementsGraphQLType(name string) bool { return name == "PublicKey" }

// UnmarshalGraphQL unmarshals the provided GraphQL query data.
func (p *PriorityPubkey) UnmarshalGraphQL(input interface{}) error {
func (p *PublicKey) UnmarshalGraphQL(input interface{}) error {
var err error
switch input := input.(type) {
case string:
err = p.UnmarshalText([]byte(input))
default:
err = fmt.Errorf("unexpected type %T for PriorityPubkey", input)
err = fmt.Errorf("unexpected type %T for PublicKey", input)
}
return err
}

// UnprefixedPriorityPubkey allows marshaling an PriorityPubkey without 0x prefix.
type UnprefixedPriorityPubkey PriorityPubkey
// UnprefixedPublicKey allows marshaling an PublicKey without 0x prefix.
type UnprefixedPublicKey PublicKey

// UnmarshalText decodes the address from hex. The 0x prefix is optional.
func (p *UnprefixedPriorityPubkey) UnmarshalText(input []byte) error {
return hexutil.UnmarshalFixedUnprefixedText("UnprefixedPriorityPubkey", input, p[:])
func (p *UnprefixedPublicKey) UnmarshalText(input []byte) error {
return hexutil.UnmarshalFixedUnprefixedText("UnprefixedPublicKey", input, p[:])
}

// MarshalText encodes the address as hex.
func (p UnprefixedPriorityPubkey) MarshalText() ([]byte, error) {
func (p UnprefixedPublicKey) MarshalText() ([]byte, error) {
return []byte(hex.EncodeToString(p[:])), nil
}
11 changes: 6 additions & 5 deletions consensus/istanbul/backend/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,12 @@ func TestVoting(t *testing.T) {

genesis := testutils.Genesis(validators)
config := istanbul.Config{
RequestTimeout: istanbul.DefaultConfig.RequestTimeout,
BlockPeriod: istanbul.DefaultConfig.BlockPeriod,
ProposerPolicy: istanbul.DefaultConfig.ProposerPolicy,
Epoch: istanbul.DefaultConfig.Epoch,
AllowedFutureBlockTime: istanbul.DefaultConfig.AllowedFutureBlockTime,
RequestTimeoutSeconds: istanbul.DefaultConfig.RequestTimeoutSeconds,
MaxRequestTimeoutSeconds: istanbul.DefaultConfig.MaxRequestTimeoutSeconds,
BlockPeriod: istanbul.DefaultConfig.BlockPeriod,
ProposerPolicy: istanbul.DefaultConfig.ProposerPolicy,
Epoch: istanbul.DefaultConfig.Epoch,
AllowedFutureBlockTime: istanbul.DefaultConfig.AllowedFutureBlockTime,
}
if tt.epoch != 0 {
config.Epoch = tt.epoch
Expand Down
22 changes: 15 additions & 7 deletions consensus/istanbul/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ func (p *ProposerPolicy) ClearRegistry() {
}

type Config struct {
RequestTimeout uint64 `toml:",omitempty"` // The timeout for each Istanbul round in milliseconds.
RequestTimeoutSeconds uint64 `toml:",omitempty"` // The timeout for each Istanbul round in seconds.
MaxRequestTimeoutSeconds uint64 `toml:",omitempty"` // Max request timeout for each Istanbul round in seconds.
BlockPeriod uint64 `toml:",omitempty"` // Default minimum difference between two consecutive block's timestamps in second
ProposerPolicy *ProposerPolicy `toml:",omitempty"` // The policy for proposer selection
Epoch uint64 `toml:",omitempty"` // The number of blocks after which to checkpoint and reset the pending votes
Expand All @@ -130,25 +131,32 @@ type Config struct {
}

var DefaultConfig = &Config{
RequestTimeout: 10000,
BlockPeriod: 5,
ProposerPolicy: NewRoundRobinProposerPolicy(),
Epoch: 30000,
AllowedFutureBlockTime: 5,
RequestTimeoutSeconds: 10,
MaxRequestTimeoutSeconds: 60,
BlockPeriod: 5,
ProposerPolicy: NewRoundRobinProposerPolicy(),
Epoch: 30000,
AllowedFutureBlockTime: 5,
}

func (c Config) GetConfig(blockNumber *big.Int) Config {
newConfig := c
for i := 0; c.Transitions != nil && i < len(c.Transitions) && c.Transitions[i].Block.Cmp(blockNumber) <= 0; i++ {
if c.Transitions[i].RequestTimeoutSeconds != 0 {
newConfig.RequestTimeout = c.Transitions[i].RequestTimeoutSeconds
newConfig.RequestTimeoutSeconds = c.Transitions[i].RequestTimeoutSeconds
}
if c.Transitions[i].EpochLength != 0 {
newConfig.Epoch = c.Transitions[i].EpochLength
}
if c.Transitions[i].BlockPeriodSeconds != 0 {
newConfig.BlockPeriod = c.Transitions[i].BlockPeriodSeconds
}
if c.Transitions[i].MaxRequestTimeoutSeconds != 0 {
newConfig.MaxRequestTimeoutSeconds = c.Transitions[i].MaxRequestTimeoutSeconds
}
if c.Transitions[i].AllowedFutureBlockTime != 0 {
newConfig.AllowedFutureBlockTime = c.Transitions[i].AllowedFutureBlockTime
}
}
return newConfig
}
Loading

0 comments on commit 2eea6bb

Please sign in to comment.