Fix geth timestamp incrementing (#14)
* Making geth only update timestamp when it is over 600s older than current timestamp. * Commenting out logic check to validate timestamp works the way it no longer works
This commit is contained in:
parent
fa42b78228
commit
1efe552752
7
.github/workflows/dev-ecr-deploy.yml
vendored
7
.github/workflows/dev-ecr-deploy.yml
vendored
@ -40,10 +40,9 @@ jobs:
|
|||||||
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
|
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
|
||||||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
|
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
|
||||||
|
|
||||||
# TODO: Add this when the DEV env is set up
|
- name: Stop existing dev-geth ECS task to auto-start task with new image
|
||||||
# - name: Stop existing dev-geth ECS task to auto-start task with new image
|
run: |
|
||||||
# run: |
|
./.github/scripts/stop-ecs-task.sh dev dev-all-in-one
|
||||||
# ./.github/scripts/stop-ecs-task.sh dev-geth geth
|
|
||||||
|
|
||||||
- name: Logout of Amazon ECR
|
- name: Logout of Amazon ECR
|
||||||
if: always()
|
if: always()
|
||||||
|
@ -13,10 +13,8 @@ RUN apk add --no-cache ca-certificates
|
|||||||
COPY --from=builder /go-ethereum/build/bin/geth /usr/local/bin/
|
COPY --from=builder /go-ethereum/build/bin/geth /usr/local/bin/
|
||||||
|
|
||||||
EXPOSE 8545 8546 8547 30303 30303/udp
|
EXPOSE 8545 8546 8547 30303 30303/udp
|
||||||
# ENTRYPOINT ["geth"]
|
|
||||||
|
|
||||||
COPY docker/entrypoint.sh /bin
|
COPY docker/entrypoint.sh /bin
|
||||||
RUN chmod +x /bin/entrypoint.sh
|
RUN chmod +x /bin/entrypoint.sh
|
||||||
|
|
||||||
EXPOSE 9545
|
|
||||||
ENTRYPOINT ["sh", "/bin/entrypoint.sh"]
|
ENTRYPOINT ["sh", "/bin/entrypoint.sh"]
|
||||||
|
@ -321,9 +321,10 @@ func (c *Clique) verifyCascadingFields(chain consensus.ChainReader, header *type
|
|||||||
if parent == nil || parent.Number.Uint64() != number-1 || parent.Hash() != header.ParentHash {
|
if parent == nil || parent.Number.Uint64() != number-1 || parent.Hash() != header.ParentHash {
|
||||||
return consensus.ErrUnknownAncestor
|
return consensus.ErrUnknownAncestor
|
||||||
}
|
}
|
||||||
if parent.Time+c.config.Period > header.Time {
|
// [REMOVED] to account for timestamp changes
|
||||||
return ErrInvalidTimestamp
|
//if parent.Time+c.config.Period > header.Time {
|
||||||
}
|
// return ErrInvalidTimestamp
|
||||||
|
//}
|
||||||
// Retrieve the snapshot needed to verify this header and cache it
|
// Retrieve the snapshot needed to verify this header and cache it
|
||||||
snap, err := c.snapshot(chain, number-1, header.ParentHash, parents)
|
snap, err := c.snapshot(chain, number-1, header.ParentHash, parents)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -543,10 +544,11 @@ func (c *Clique) Prepare(chain consensus.ChainReader, header *types.Header) erro
|
|||||||
if parent == nil {
|
if parent == nil {
|
||||||
return consensus.ErrUnknownAncestor
|
return consensus.ErrUnknownAncestor
|
||||||
}
|
}
|
||||||
header.Time = parent.Time + c.config.Period
|
// [REMOVED] so we can control timestamps
|
||||||
if header.Time < uint64(time.Now().Unix()) {
|
//header.Time = parent.Time + c.config.Period
|
||||||
header.Time = uint64(time.Now().Unix())
|
//if header.Time < uint64(time.Now().Unix()) {
|
||||||
}
|
// header.Time = uint64(time.Now().Unix())
|
||||||
|
//}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,7 +237,6 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
|
|||||||
bc.currentFastBlock.Store(nilBlock)
|
bc.currentFastBlock.Store(nilBlock)
|
||||||
|
|
||||||
// TODO: Make default current timestamp configurable & make 0 if genesis else load from last block?
|
// TODO: Make default current timestamp configurable & make 0 if genesis else load from last block?
|
||||||
bc.SetCurrentTimestamp(int64(0))
|
|
||||||
|
|
||||||
// Initialize the chain with ancient data if it isn't empty.
|
// Initialize the chain with ancient data if it isn't empty.
|
||||||
if bc.empty() {
|
if bc.empty() {
|
||||||
@ -252,6 +251,13 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
|
|||||||
// it in advance.
|
// it in advance.
|
||||||
bc.engine.VerifyHeader(bc, bc.CurrentHeader(), true)
|
bc.engine.VerifyHeader(bc, bc.CurrentHeader(), true)
|
||||||
|
|
||||||
|
if currentHeader := bc.CurrentHeader(); currentHeader != nil {
|
||||||
|
log.Debug("Read timestamp from last block. ", "timestamp", bc.CurrentHeader().Time)
|
||||||
|
bc.SetCurrentTimestamp(int64(bc.CurrentHeader().Time))
|
||||||
|
} else {
|
||||||
|
bc.SetCurrentTimestamp(int64(0))
|
||||||
|
}
|
||||||
|
|
||||||
if frozen, err := bc.db.Ancients(); err == nil && frozen > 0 {
|
if frozen, err := bc.db.Ancients(); err == nil && frozen > 0 {
|
||||||
var (
|
var (
|
||||||
needRewind bool
|
needRewind bool
|
||||||
|
21
docker-compose.yml
Normal file
21
docker-compose.yml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
version: "3"
|
||||||
|
|
||||||
|
services:
|
||||||
|
geth_l2:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
volumes:
|
||||||
|
- l2-node-data:/mnt/l2-node/l2:rw
|
||||||
|
environment:
|
||||||
|
- CLEAR_DATA_KEY
|
||||||
|
- TARGET_GAS_LIMIT
|
||||||
|
- VOLUME_PATH=/mnt/l2-node/l2
|
||||||
|
- HOSTNAME=geth_l2
|
||||||
|
- PORT=8545
|
||||||
|
- NETWORK_ID=108
|
||||||
|
ports:
|
||||||
|
- 8545:8545
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
l2-node-data:
|
@ -74,6 +74,9 @@ const (
|
|||||||
|
|
||||||
// staleThreshold is the maximum depth of the acceptable stale block.
|
// staleThreshold is the maximum depth of the acceptable stale block.
|
||||||
staleThreshold = 7
|
staleThreshold = 7
|
||||||
|
|
||||||
|
maxClockSkewSeconds = 600 // 10 mins for now
|
||||||
|
timestampDelaySeconds = 300 // 5 mins for now
|
||||||
)
|
)
|
||||||
|
|
||||||
// environment is the worker's current environment and holds all of the current state information.
|
// environment is the worker's current environment and holds all of the current state information.
|
||||||
@ -220,6 +223,7 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus
|
|||||||
go worker.newWorkLoop(recommit)
|
go worker.newWorkLoop(recommit)
|
||||||
go worker.resultLoop()
|
go worker.resultLoop()
|
||||||
go worker.taskLoop()
|
go worker.taskLoop()
|
||||||
|
go worker.timestampLoop()
|
||||||
|
|
||||||
// Submit first work to initialize pending state.
|
// Submit first work to initialize pending state.
|
||||||
if init {
|
if init {
|
||||||
@ -362,6 +366,7 @@ func (w *worker) newWorkLoop(recommit time.Duration) {
|
|||||||
timer.Reset(recommit)
|
timer.Reset(recommit)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
timestamp = w.chain.CurrentTimestamp()
|
||||||
commit(true, commitInterruptResubmit)
|
commit(true, commitInterruptResubmit)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -613,6 +618,31 @@ func (w *worker) resultLoop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// timestampLoop is a loop that updates the timestamp used for blocks when it
|
||||||
|
// is stale by more than a certain threshold.
|
||||||
|
// TODO: Re-think this as everything comes together more.
|
||||||
|
func (w *worker) timestampLoop() {
|
||||||
|
timer := time.NewTimer(0)
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-timer.C:
|
||||||
|
currentTime := time.Now().Unix()
|
||||||
|
skew := currentTime - w.chain.CurrentTimestamp()
|
||||||
|
if skew > maxClockSkewSeconds {
|
||||||
|
newTime := currentTime - timestampDelaySeconds
|
||||||
|
w.chain.SetCurrentTimestamp(newTime)
|
||||||
|
timer.Reset((maxClockSkewSeconds - timestampDelaySeconds) * time.Second)
|
||||||
|
log.Debug("timestamp above max clock skew", "maxSkew", maxClockSkewSeconds, "overBy", timestampDelaySeconds, "newTime", newTime)
|
||||||
|
} else {
|
||||||
|
timer.Reset(time.Duration(maxClockSkewSeconds-skew) * time.Second)
|
||||||
|
}
|
||||||
|
case <-w.exitCh:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// makeCurrent creates a new environment for the current cycle.
|
// makeCurrent creates a new environment for the current cycle.
|
||||||
func (w *worker) makeCurrent(parent *types.Block, header *types.Header) error {
|
func (w *worker) makeCurrent(parent *types.Block, header *types.Header) error {
|
||||||
state, err := w.chain.StateAt(parent.Root())
|
state, err := w.chain.StateAt(parent.Root())
|
||||||
|
Loading…
Reference in New Issue
Block a user