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

Fixed hive test on invalid transition payload #4618

Merged
merged 4 commits into from
Jul 3, 2022
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
32 changes: 24 additions & 8 deletions cmd/rpcdaemon/commands/engine_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,25 @@ func (e *EngineImpl) ForkchoiceUpdatedV1(ctx context.Context, forkChoiceState *F
return nil, err
}

payloadStatus := convertPayloadStatus(reply.PayloadStatus)
if reply.PayloadStatus.Status == remote.EngineStatus_INVALID && payloadStatus["latestValidHash"] != nil {
tx, err := e.db.BeginRo(ctx)
if err != nil {
return nil, err
}

defer tx.Rollback()
latestValidHash := payloadStatus["latestValidHash"].(common.Hash)
isValidHashPos, err := rawdb.IsPosBlock(tx, latestValidHash)
if err != nil {
return nil, err
}
if !isValidHashPos {
payloadStatus["latestValidHash"] = common.Hash{}
}
}
json := map[string]interface{}{
"payloadStatus": convertPayloadStatus(reply.PayloadStatus),
"payloadStatus": payloadStatus,
}
if reply.PayloadId != 0 {
encodedPayloadId := make([]byte, 8)
Expand All @@ -128,13 +145,6 @@ func (e *EngineImpl) ForkchoiceUpdatedV1(ctx context.Context, forkChoiceState *F
func (e *EngineImpl) NewPayloadV1(ctx context.Context, payload *ExecutionPayload) (map[string]interface{}, error) {
log.Trace("Received NewPayload", "height", uint64(payload.BlockNumber), "hash", payload.BlockHash)

tx, err := e.db.BeginRo(ctx)
if err != nil {
return nil, err
}

defer tx.Rollback()

var baseFee *uint256.Int
if payload.BaseFeePerGas != nil {
var overflow bool
Expand Down Expand Up @@ -172,6 +182,12 @@ func (e *EngineImpl) NewPayloadV1(ctx context.Context, payload *ExecutionPayload
}
payloadStatus := convertPayloadStatus(res)
if payloadStatus["latestValidHash"] != nil {
tx, err := e.db.BeginRo(ctx)
if err != nil {
return nil, err
}

defer tx.Rollback()
latestValidHash := payloadStatus["latestValidHash"].(common.Hash)
isValidHashPos, err := rawdb.IsPosBlock(tx, latestValidHash)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions turbo/stages/headerdownload/header_algos.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,9 @@ func (hi *HeaderInserter) FeedHeaderPoS(db kv.GetPut, header *types.Header, hash
return fmt.Errorf("[%s] failed to WriteTd: %w", hi.logPrefix, err)
}
rawdb.WriteHeader(db, header)
if err = rawdb.WriteHeaderNumber(db, hash, blockHeight); err != nil {
return err
}

hi.highest = blockHeight
hi.highestHash = hash
Expand Down