chore: set empty hash to hash of nothing (#20775)

This commit is contained in:
Marko
2024-07-02 14:15:44 +00:00
committed by GitHub
parent 1bc857c417
commit 4e6507462e
5 changed files with 67 additions and 60 deletions
+40
View File
@@ -4,6 +4,7 @@ import (
"context"
"cosmossdk.io/core/header"
"cosmossdk.io/core/store"
)
var _ header.Service = (*HeaderService)(nil)
@@ -13,3 +14,42 @@ type HeaderService struct{}
func (h HeaderService) HeaderInfo(ctx context.Context) header.Info {
return ctx.(*executionContext).headerInfo
}
const headerInfoPrefix = 0x37
// setHeaderInfo sets the header info in the state to be used by queries in the future.
func (s STF[T]) setHeaderInfo(state store.WriterMap, headerInfo header.Info) error {
// TODO storing header info is too low level here, stf should be stateless.
// We should have a keeper that does this.
runtimeStore, err := state.GetWriter(Identity)
if err != nil {
return err
}
bz, err := headerInfo.Bytes()
if err != nil {
return err
}
err = runtimeStore.Set([]byte{headerInfoPrefix}, bz)
if err != nil {
return err
}
return nil
}
// getHeaderInfo gets the header info from the state. It should only be used for queries
func (s STF[T]) getHeaderInfo(state store.WriterMap) (i header.Info, err error) {
runtimeStore, err := state.GetWriter(Identity)
if err != nil {
return header.Info{}, err
}
v, err := runtimeStore.Get([]byte{headerInfoPrefix})
if err != nil {
return header.Info{}, err
}
if v == nil {
return header.Info{}, nil
}
err = i.FromBytes(v)
return i, err
}
-39
View File
@@ -421,45 +421,6 @@ func (s STF[T]) validatorUpdates(
return ctx.events, valSetUpdates, nil
}
const headerInfoPrefix = 0x37
// setHeaderInfo sets the header info in the state to be used by queries in the future.
func (s STF[T]) setHeaderInfo(state store.WriterMap, headerInfo header.Info) error {
// TODO storing header info is too low level here, stf should be stateless.
// We should have a keeper that does this.
runtimeStore, err := state.GetWriter(Identity)
if err != nil {
return err
}
bz, err := headerInfo.Bytes()
if err != nil {
return err
}
err = runtimeStore.Set([]byte{headerInfoPrefix}, bz)
if err != nil {
return err
}
return nil
}
// getHeaderInfo gets the header info from the state. It should only be used for queries
func (s STF[T]) getHeaderInfo(state store.WriterMap) (i header.Info, err error) {
runtimeStore, err := state.GetWriter(Identity)
if err != nil {
return header.Info{}, err
}
v, err := runtimeStore.Get([]byte{headerInfoPrefix})
if err != nil {
return header.Info{}, err
}
if v == nil {
return header.Info{}, nil
}
err = i.FromBytes(v)
return i, err
}
// Simulate simulates the execution of a tx on the provided state.
func (s STF[T]) Simulate(
ctx context.Context,