From a6f3fbfbeb7ea94bda6369a7163a523e118a123c Mon Sep 17 00:00:00 2001 From: yihuang Date: Wed, 10 Apr 2024 18:09:25 +0800 Subject: [PATCH] optim: shallow copy block header in Context (#19966) --- CHANGELOG.md | 1 + types/context.go | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 419f2ec401e..889ff770c57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -92,6 +92,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (types) [#18963](https://github.com/cosmos/cosmos-sdk/pull/18963) Swap out amino json encoding of `ABCIMessageLogs` for std lib json encoding * (x/auth) [#19651](https://github.com/cosmos/cosmos-sdk/pull/19651) Allow empty public keys in `GetSignBytesAdapter`. * (x/genutil) [#19735](https://github.com/cosmos/cosmos-sdk/pull/19735) Update genesis api to match new `appmodule.HasGenesis` interface. +* (server) [#19966](https://github.com/cosmos/cosmos-sdk/pull/19966) Return BlockHeader by shallow copy in server Context. ### Bug Fixes diff --git a/types/context.go b/types/context.go index 2c63445f870..49b25a4f072 100644 --- a/types/context.go +++ b/types/context.go @@ -6,7 +6,6 @@ import ( abci "github.com/cometbft/cometbft/abci/types" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" - "github.com/cosmos/gogoproto/proto" "cosmossdk.io/core/comet" "cosmossdk.io/core/header" @@ -91,10 +90,9 @@ func (c Context) StreamingManager() storetypes.StreamingManager { return c.strea func (c Context) CometInfo() comet.Info { return c.cometInfo } func (c Context) HeaderInfo() header.Info { return c.headerInfo } -// clone the header before returning +// BlockHeader returns the header by value. func (c Context) BlockHeader() cmtproto.Header { - msg := proto.Clone(&c.header).(*cmtproto.Header) - return *msg + return c.header } // HeaderHash returns a copy of the header hash obtained during abci.RequestBeginBlock