Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed basefee and replaced with a gas price auction #2151

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/go-quai/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func runStart(cmd *cobra.Command, args []string) error {
}
// Start the hierarchical co-ordinator
var nodeWg sync.WaitGroup
hc := utils.NewHierarchicalCoordinator(node, logLevel, &nodeWg, startingExpansionNumber, quitCh)
hc := utils.NewHierarchicalCoordinator(node, logLevel, &nodeWg, startingExpansionNumber)
err = hc.StartHierarchicalCoordinator()
if err != nil {
log.Global.WithField("error", err).Fatal("error starting hierarchical coordinator")
Expand All @@ -110,6 +110,7 @@ func runStart(cmd *cobra.Command, args []string) error {
<-ch
log.Global.Warn("Received 'stop' signal, shutting down gracefully...")
cancel()
node.Close()
// stop the hierarchical co-ordinator
hc.Stop()
if err := node.Stop(); err != nil {
Expand Down
94 changes: 34 additions & 60 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/dominant-strategies/go-quai/metrics_config"
"github.com/dominant-strategies/go-quai/node"
"github.com/dominant-strategies/go-quai/params"
"github.com/dominant-strategies/go-quai/quai/gasprice"
"github.com/dominant-strategies/go-quai/quai/quaiconfig"
)

Expand Down Expand Up @@ -105,10 +104,6 @@ var NodeFlags = []Flag{
VMEnableDebugFlag,
PprofFlag,
InsecureUnlockAllowedFlag,
GpoBlocksFlag,
GpoPercentileFlag,
GpoMaxGasPriceFlag,
GpoIgnoreGasPriceFlag,
CoinbaseAddressFlag,
EnvironmentFlag,
QuaiStatsURLFlag,
Expand Down Expand Up @@ -501,30 +496,6 @@ var (
Usage: "Allow insecure account unlocking when account-related RPCs are exposed by http" + generateEnvDoc(c_NodeFlagPrefix+"allow-insecure-unlock"),
}

GpoBlocksFlag = Flag{
Name: c_NodeFlagPrefix + "gpo-blocks",
Value: quaiconfig.Defaults.GPO.Blocks,
Usage: "Number of recent blocks to check for gas prices" + generateEnvDoc(c_NodeFlagPrefix+"gpo-blocks"),
}

GpoPercentileFlag = Flag{
Name: c_NodeFlagPrefix + "gpo-percentile",
Value: quaiconfig.Defaults.GPO.Percentile,
Usage: "Suggested gas price is the given percentile of a set of recent transaction gas prices" + generateEnvDoc(c_NodeFlagPrefix+"gpo-percentile"),
}

GpoMaxGasPriceFlag = Flag{
Name: c_NodeFlagPrefix + "gpo-maxprice",
Value: quaiconfig.Defaults.GPO.MaxPrice.Int64(),
Usage: "Maximum gas price will be recommended by gpo" + generateEnvDoc(c_NodeFlagPrefix+"gpo-maxprice"),
}

GpoIgnoreGasPriceFlag = Flag{
Name: c_NodeFlagPrefix + "gpo-ignoreprice",
Value: quaiconfig.Defaults.GPO.IgnorePrice.Int64(),
Usage: "Gas price below which gpo will ignore transactions" + generateEnvDoc(c_NodeFlagPrefix+"gpo-ignoreprice"),
}

CoinbaseAddressFlag = Flag{
Name: c_NodeFlagPrefix + "coinbases",
Value: "",
Expand Down Expand Up @@ -766,15 +737,26 @@ func ParseCoinbaseAddresses() (map[string]string, error) {

for _, coinbase := range strings.Split(coinbaseInput, ",") {
coinbase = strings.TrimSpace(coinbase)
address := common.FromHex(coinbase)
location := common.LocationFromAddressBytes(address)
if _, exists := coinbases[location.Name()]; exists {
log.Global.WithField("shard", location.Name()).Fatalf("Duplicate coinbase address for shard")
address := common.HexToAddress(coinbase, common.Location{0, 0})
location := address.Location()

// check if the primary key exists, otherwise, the first address in the given shard becomes the primary coinbase
// second one becomes the secondary coinbase
primaryCoinbaseKey := location.Name() + "primary"
if _, exists := coinbases[primaryCoinbaseKey]; exists {
// add this address to the secondary coinbases list
secondaryCoinbaseKey := location.Name() + "secondary"
if _, exists := coinbases[secondaryCoinbaseKey]; exists {
log.Global.WithField("key", secondaryCoinbaseKey).Fatalf("Duplicate secondary coinbase address for the given ledger in the shard")
}
coinbases[secondaryCoinbaseKey] = coinbase
} else {
coinbases[primaryCoinbaseKey] = coinbase
}

if err := isValidAddress(coinbase); err != nil {
log.Global.WithField("err", err).Fatalf("Error parsing coinbase addresses")
}
coinbases[location.Name()] = coinbase
}

log.Global.Infof("Coinbase Addresses: %v", coinbases)
Expand Down Expand Up @@ -978,22 +960,30 @@ func HexAddress(account string, nodeLocation common.Location) (common.Address, e
return common.Address{}, errors.New("invalid account address")
}

// setEtherbase retrieves the etherbase either from the directly specified
// setCoinbase retrieves the etherbase either from the directly specified
// command line flags or from the keystore if CLI indexed.
func setEtherbase(cfg *quaiconfig.Config) {
func setCoinbase(cfg *quaiconfig.Config) {
coinbaseMap, err := ParseCoinbaseAddresses()
if err != nil {
log.Global.Fatalf("error parsing coinbase addresses: %s", err)
}
// TODO: Have to handle more shards in the future
etherbase := coinbaseMap[cfg.NodeLocation.Name()]
// Convert the etherbase into an address and configure it
if etherbase != "" {
account, err := HexAddress(etherbase, cfg.NodeLocation)
primaryCoinbase := coinbaseMap[cfg.NodeLocation.Name()+"primary"]
secondaryCoinbase := coinbaseMap[cfg.NodeLocation.Name()+"secondary"]
// Convert the coinbase into an address and configure it
if primaryCoinbase != "" {
account, err := HexAddress(primaryCoinbase, cfg.NodeLocation)
if err != nil {
Fatalf("Invalid miner etherbase: %v", err)
Fatalf("Invalid primary coinbase: %v", err)
}
cfg.Miner.Etherbase = account
cfg.Miner.PrimaryCoinbase = account
}
// Convert the coinbase into an address and configure it
if secondaryCoinbase != "" {
account, err := HexAddress(secondaryCoinbase, cfg.NodeLocation)
if err != nil {
Fatalf("Invalid secondary coinbase: %v", err)
}
cfg.Miner.SecondaryCoinbase = account
}
}

Expand Down Expand Up @@ -1071,21 +1061,6 @@ func setDataDir(cfg *node.Config) {
}
}

func setGPO(cfg *gasprice.Config) {
if viper.IsSet(GpoBlocksFlag.Name) {
cfg.Blocks = viper.GetInt(GpoBlocksFlag.Name)
}
if viper.IsSet(GpoPercentileFlag.Name) {
cfg.Percentile = viper.GetInt(GpoPercentileFlag.Name)
}
if viper.IsSet(GpoMaxGasPriceFlag.Name) {
cfg.MaxPrice = big.NewInt(viper.GetInt64(GpoMaxGasPriceFlag.Name))
}
if viper.IsSet(GpoIgnoreGasPriceFlag.Name) {
cfg.IgnorePrice = big.NewInt(viper.GetInt64(GpoIgnoreGasPriceFlag.Name))
}
}

func setTxPool(cfg *core.TxPoolConfig, nodeLocation common.Location) {
if viper.IsSet(TxPoolLocalsFlag.Name) && viper.GetString(TxPoolLocalsFlag.Name) != "" {
locals := strings.Split(viper.GetString(TxPoolLocalsFlag.Name), ",")
Expand Down Expand Up @@ -1290,9 +1265,8 @@ func SetQuaiConfig(stack *node.Node, cfg *quaiconfig.Config, slicesRunning []com

// only set etherbase if its a zone chain
if len(nodeLocation) == 2 {
setEtherbase(cfg)
setCoinbase(cfg)
}
setGPO(&cfg.GPO)
setTxPool(&cfg.TxPool, nodeLocation)

// If blake3 consensus engine is specifically asked use the blake3 engine
Expand Down
56 changes: 16 additions & 40 deletions cmd/utils/hierarchical_coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func (ns *NodeSet) Copy() NodeSet {
}

// NewHierarchicalCoordinator creates a new instance of the HierarchicalCoordinator
func NewHierarchicalCoordinator(p2p quai.NetworkingAPI, logLevel string, nodeWg *sync.WaitGroup, startingExpansionNumber uint64, quitCh chan struct{}) *HierarchicalCoordinator {
func NewHierarchicalCoordinator(p2p quai.NetworkingAPI, logLevel string, nodeWg *sync.WaitGroup, startingExpansionNumber uint64) *HierarchicalCoordinator {
db, err := OpenBackendDB()
if err != nil {
log.Global.WithField("err", err).Fatal("Error opening the backend db")
Expand All @@ -275,7 +275,7 @@ func NewHierarchicalCoordinator(p2p quai.NetworkingAPI, logLevel string, nodeWg
logLevel: logLevel,
slicesRunning: GetRunningZones(),
treeExpansionTriggerStarted: false,
quitCh: quitCh,
quitCh: make(chan struct{}),
recentBlocks: make(map[string]*lru.Cache[common.Hash, Node]),
pendingHeaders: NewPendingHeaders(),
bestEntropy: new(big.Int).Set(common.Big0),
Expand Down Expand Up @@ -434,12 +434,12 @@ func (hc *HierarchicalCoordinator) startNode(logPath string, quaiBackend quai.Co
}

func (hc *HierarchicalCoordinator) Stop() {
close(hc.quitCh)
for _, chainEventSub := range hc.chainSubs {
chainEventSub.Unsubscribe()
}
hc.expansionSub.Unsubscribe()
hc.db.Close()
close(hc.quitCh)
hc.wg.Wait()
}

Expand Down Expand Up @@ -484,7 +484,8 @@ func (hc *HierarchicalCoordinator) expansionEventLoop() {
}
}
}

case <-hc.quitCh:
return
case <-hc.expansionSub.Err():
return
}
Expand Down Expand Up @@ -617,6 +618,8 @@ func (hc *HierarchicalCoordinator) ChainEventLoop(chainEvent chan core.ChainEven
hc.pendingHeaderBackupCh <- struct{}{}
lastUpdateTime = time.Now()
}
case <-hc.quitCh:
return
case <-sub.Err():
return
}
Expand All @@ -641,7 +644,6 @@ func (hc *HierarchicalCoordinator) MapConstructProc() {
hc.PendingHeadersMap()
case <-hc.quitCh:
return
default:
}
}
}
Expand Down Expand Up @@ -837,44 +839,18 @@ func (hc *HierarchicalCoordinator) ReapplicationLoop(head core.ChainEvent) {
sleepTime := 1

for {
hc.BuildPendingHeaders(head.Block, head.Order, head.Entropy)
time.Sleep(time.Duration(sleepTime) * time.Second)
sleepTime = sleepTime * 2
if sleepTime > 65 {
break
}
}
}

func (hc *HierarchicalCoordinator) GetLock(location common.Location, order int) []*sync.RWMutex {
hc.mutexMapMu.Lock()
defer hc.mutexMapMu.Unlock()
_, exists := hc.pendingHeaderMu[location.Name()]
if !exists {
hc.pendingHeaderMu[location.Name()] = &sync.RWMutex{}
}

regionNum, zoneNum := common.GetHierarchySizeForExpansionNumber(hc.currentExpansionNumber)
var locks []*sync.RWMutex
switch order {
case common.PRIME_CTX:
locks = append(locks, hc.pendingHeaderMu[common.Location{}.Name()])
for i := 0; i < int(regionNum); i++ {
locks = append(locks, hc.pendingHeaderMu[common.Location{byte(i)}.Name()])
for j := 0; j < int(zoneNum); j++ {
locks = append(locks, hc.pendingHeaderMu[common.Location{byte(i), byte(j)}.Name()])
select {
case <-hc.quitCh:
return
default:
hc.BuildPendingHeaders(head.Block, head.Order, head.Entropy)
time.Sleep(time.Duration(sleepTime) * time.Second)
sleepTime = sleepTime * 2
if sleepTime > 65 {
return
}
}
case common.REGION_CTX:
locks = append(locks, hc.pendingHeaderMu[common.Location{byte(location.Region())}.Name()])
for j := 0; j < int(zoneNum); j++ {
locks = append(locks, hc.pendingHeaderMu[common.Location{byte(location.Region()), byte(j)}.Name()])
}
case common.ZONE_CTX:
locks = append(locks, hc.pendingHeaderMu[common.Location{byte(location.Region()), byte(location.Zone())}.Name()])
}

return locks
}

func (hc *HierarchicalCoordinator) CalculateLeaders(badHashes map[common.Hash]bool) []Node {
Expand Down
2 changes: 1 addition & 1 deletion common/proto_common.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 18 additions & 13 deletions consensus/blake3pow/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var (
// Author implements consensus.Engine, returning the header's coinbase as the
// proof-of-work verified author of the block.
func (blake3pow *Blake3pow) Author(header *types.WorkObject) (common.Address, error) {
return header.Coinbase(), nil
return header.PrimaryCoinbase(), nil
}

// VerifyHeader checks whether a header conforms to the consensus rules of the
Expand Down Expand Up @@ -416,9 +416,24 @@ func (blake3pow *Blake3pow) verifyHeader(chain consensus.ChainHeaderReader, head
}
if nodeCtx == common.ZONE_CTX {
// check if the header coinbase is in scope
_, err := header.Coinbase().InternalAddress()
_, err := header.PrimaryCoinbase().InternalAddress()
if err != nil {
return fmt.Errorf("out-of-scope coinbase in the header: %v location: %v nodeLocation: %v", header.Coinbase(), header.Location(), blake3pow.config.NodeLocation)
return fmt.Errorf("out-of-scope primary coinbase in the header: %v location: %v nodeLocation: %v", header.PrimaryCoinbase(), header.Location(), blake3pow.config.NodeLocation)
}
_, err = header.SecondaryCoinbase().InternalAddress()
if err != nil {
return fmt.Errorf("out-of-scope secondary coinbase in the header: %v location: %v nodeLocation: %v", header.SecondaryCoinbase(), header.Location(), blake3pow.config.NodeLocation)
}
// One of the coinbases has to be Quai and the other one has to be Qi
quaiAddress := header.PrimaryCoinbase().IsInQuaiLedgerScope()
if quaiAddress {
if !header.SecondaryCoinbase().IsInQiLedgerScope() {
return fmt.Errorf("primary coinbase: %v is in quai ledger but secondary coinbase: %v is not in Qi ledger", header.PrimaryCoinbase(), header.SecondaryCoinbase())
}
} else {
if !header.SecondaryCoinbase().IsInQuaiLedgerScope() {
return fmt.Errorf("primary coinbase: %v is in qi ledger but secondary coinbase: %v is not in Quai ledger", header.PrimaryCoinbase(), header.SecondaryCoinbase())
}
}
// Verify that the gas limit is <= 2^63-1
cap := uint64(0x7fffffffffffffff)
Expand All @@ -436,16 +451,6 @@ func (blake3pow *Blake3pow) verifyHeader(chain consensus.ChainHeaderReader, head
return fmt.Errorf("invalid gasLimit: have %d, want %d",
header.GasLimit(), expectedGasLimit)
}
// Verify the header is not malformed
if header.BaseFee() == nil {
return fmt.Errorf("header is missing baseFee")
}
// Verify the baseFee is correct based on the parent header.
expectedBaseFee := misc.CalcBaseFee(chain.Config(), parent)
if header.BaseFee().Cmp(expectedBaseFee) != 0 {
return fmt.Errorf("invalid baseFee: have %s, want %s, parentBaseFee %s, parentGasUsed %d",
expectedBaseFee, header.BaseFee(), parent.BaseFee(), parent.GasUsed())
}
// Verify that the stateUsed is <= stateLimit
if header.StateUsed() > header.StateLimit() {
return fmt.Errorf("invalid stateUsed: have %d, stateLimit %d", header.StateUsed(), header.StateLimit())
Expand Down
Loading
Loading