mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
foobarbazbat
This commit is contained in:
parent
41abab9e39
commit
47d5b4fc21
1 changed files with 24 additions and 18 deletions
|
|
@ -37,38 +37,44 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const devEpochLength = 32
|
const devEpochLength = 32
|
||||||
|
const maxWithdrawalCount = 10
|
||||||
|
|
||||||
// withdrawalQueue implements a FIFO queue which holds withdrawals that are
|
// withdrawalQueue implements a FIFO queue which holds withdrawals that are
|
||||||
// pending inclusion.
|
// pending inclusion.
|
||||||
type withdrawalQueue struct {
|
type withdrawalQueue struct {
|
||||||
pending chan *types.Withdrawal
|
queue types.Withdrawals
|
||||||
|
pending chan struct{}
|
||||||
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// add queues a withdrawal for future inclusion.
|
// add queues a withdrawal for future inclusion.
|
||||||
func (w *withdrawalQueue) add(withdrawal *types.Withdrawal) error {
|
func (w *withdrawalQueue) add(withdrawal *types.Withdrawal) error {
|
||||||
select {
|
w.mu.Lock()
|
||||||
case w.pending <- withdrawal:
|
defer w.mu.Unlock()
|
||||||
break
|
|
||||||
default:
|
if len(w.queue)+1 > maxWithdrawalCount {
|
||||||
return errors.New("withdrawal queue full")
|
return errors.New("withdrawal queue full")
|
||||||
}
|
}
|
||||||
|
w.queue = append(w.queue, withdrawal)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// gatherPending returns a number of queued withdrawals up to a maximum count.
|
// gatherPending returns a number of queued withdrawals up to a maximum count.
|
||||||
func (w *withdrawalQueue) gatherPending(maxCount int) []*types.Withdrawal {
|
func (w *withdrawalQueue) gatherPending(gatherCount int) []*types.Withdrawal {
|
||||||
withdrawals := []*types.Withdrawal{}
|
w.mu.Lock()
|
||||||
for {
|
defer w.mu.Unlock()
|
||||||
select {
|
|
||||||
case withdrawal := <-w.pending:
|
if gatherCount > len(w.queue) {
|
||||||
withdrawals = append(withdrawals, withdrawal)
|
gatherCount = len(w.queue)
|
||||||
if len(withdrawals) == maxCount {
|
|
||||||
return withdrawals
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return withdrawals
|
|
||||||
}
|
}
|
||||||
|
return w.queue[:gatherCount]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *withdrawalQueue) popFront(count int) {
|
||||||
|
w.mu.Lock()
|
||||||
|
defer w.mu.Unlock()
|
||||||
|
|
||||||
|
w.queue = w.queue[count:]
|
||||||
}
|
}
|
||||||
|
|
||||||
type SimulatedBeacon struct {
|
type SimulatedBeacon struct {
|
||||||
|
|
@ -112,7 +118,7 @@ func NewSimulatedBeacon(period uint64, eth *eth.Ethereum) (*SimulatedBeacon, err
|
||||||
engineAPI: engineAPI,
|
engineAPI: engineAPI,
|
||||||
lastBlockTime: block.Time,
|
lastBlockTime: block.Time,
|
||||||
curForkchoiceState: current,
|
curForkchoiceState: current,
|
||||||
withdrawals: withdrawalQueue{make(chan *types.Withdrawal, 20)},
|
withdrawals: withdrawalQueue{pending: make(chan struct{})},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue