Skip to content

Commit

Permalink
Merge branch 'main' into await-server-shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
rauljordan authored Dec 6, 2024
2 parents 490d0ae + 3f20931 commit c03d040
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 29 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Additional Use Grant: You may use the Licensed Work in a production environment
validating the correctness of the posted chain state, or to deploy
and operate (x) a blockchain that settles to a Covered Arbitrum Chain
or (y) a blockchain in accordance with, and subject to, the [Arbitrum
Expansion Program Term of Use](https://docs.arbitrum.foundation/assets/files/Arbitrum%20Expansion%20Program%20Jan182024-4f08b0c2cb476a55dc153380fa3e64b0.pdf). For purposes of this
Expansion Program Term of Use](https://docs.arbitrum.foundation/aep/ArbitrumExpansionProgramTerms.pdf). For purposes of this
Additional Use Grant, the "Covered Arbitrum Chains" are
(a) Arbitrum One (chainid:42161), Arbitrum Nova (chainid:42170),
Arbitrum Rinkeby testnet/Rinkarby (chainid:421611),Arbitrum Nitro
Expand Down
44 changes: 16 additions & 28 deletions assertions/poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"
"time"

"github.com/ccoveille/go-safecast"
"github.com/pkg/errors"

"github.com/ethereum/go-ethereum/log"
Expand Down Expand Up @@ -204,37 +203,26 @@ func (m *Manager) waitToPostIfNeeded(
ctx context.Context,
parentCreationInfo *protocol.AssertionCreatedInfo,
) error {
latestBlockNumber, err := m.backend.HeaderU64(ctx)
if err != nil {
return err
}
blocksSinceLast := uint64(0)
if parentCreationInfo.CreationBlock < latestBlockNumber {
blocksSinceLast = latestBlockNumber - parentCreationInfo.CreationBlock
}
minPeriodBlocks := m.chain.MinAssertionPeriodBlocks()
canPostNow := blocksSinceLast >= minPeriodBlocks

// If we cannot post just yet, we can wait.
if !canPostNow {
var blocksLeftForConfirmation int64
if minPeriodBlocks > blocksSinceLast {
blocksLeftForConfirmation = 0
} else {
blocksLeftForConfirmation, err = safecast.ToInt64(minPeriodBlocks - blocksSinceLast)
if err != nil {
return errors.Wrap(err, "could not convert blocks left for confirmation to int64")
}
for {
latestBlockNumber, err := m.backend.HeaderU64(ctx)
if err != nil {
return err
}
blocksSinceLast := uint64(0)
if parentCreationInfo.CreationBlock < latestBlockNumber {
blocksSinceLast = latestBlockNumber - parentCreationInfo.CreationBlock
}
if blocksSinceLast >= minPeriodBlocks {
return nil
}
timeToWait := m.times.avgBlockTime * time.Duration(blocksLeftForConfirmation)
// If we cannot post just yet, we can wait.
log.Info(
fmt.Sprintf(
"Need to wait %d blocks before posting next assertion, waiting for %v",
blocksLeftForConfirmation,
timeToWait,
fmt.Sprintf("Need to wait %d blocks before posting next assertion. Current block number: %d",
minPeriodBlocks-blocksSinceLast,
latestBlockNumber,
),
)
<-time.After(timeToWait)
<-time.After(m.times.avgBlockTime)
}
return nil
}

0 comments on commit c03d040

Please sign in to comment.