From a48066b64a7fe1298b71fcc4a49dc3fdfefcdf83 Mon Sep 17 00:00:00 2001 From: Sergi Rene Date: Wed, 16 Oct 2024 18:40:10 +0200 Subject: [PATCH] fix + test --- block/executor.go | 2 +- block/state.go | 1 + block/submit.go | 27 ++---- block/submit_test.go | 2 + proto/types/dymint/state.proto | 3 + types/pb/dymint/state.pb.go | 155 ++++++++++++++++++++++----------- types/serialization.go | 25 +++--- types/state.go | 3 + 8 files changed, 134 insertions(+), 84 deletions(-) diff --git a/block/executor.go b/block/executor.go index a83e0e8d4..00eca0380 100644 --- a/block/executor.go +++ b/block/executor.go @@ -261,7 +261,7 @@ func (e *Executor) ExecuteBlock(block *types.Block) (*tmstate.ABCIResponses, err Votes: nil, }, ByzantineValidators: nil, - ConsensusMessages: block.Data.ConsensusMessages, + //ConsensusMessages: block.Data.ConsensusMessages, }) if err != nil { return nil, err diff --git a/block/state.go b/block/state.go index 8b463f80e..097360e1c 100644 --- a/block/state.go +++ b/block/state.go @@ -111,6 +111,7 @@ func (e *Executor) UpdateStateAfterInitChain(s *types.State, res *abci.ResponseI } // We update the last results hash with the empty hash, to conform with RFC-6962. copy(s.LastResultsHash[:], merkle.HashFromByteSlices(nil)) + s.LastSubmittedBlockTime = time.Now() } func (e *Executor) UpdateMempoolAfterInitChain(s *types.State) { diff --git a/block/submit.go b/block/submit.go index 96835715d..19f245dff 100644 --- a/block/submit.go +++ b/block/submit.go @@ -32,7 +32,7 @@ func (m *Manager) SubmitLoop(ctx context.Context, bytesProduced, m.Conf.BatchSkew, m.GetUnsubmittedBlocks, - m.GetTimeSkew, + m.State.GetSkewTime, m.Conf.BatchSubmitTime, m.Conf.BatchSubmitBytes, m.CreateAndSubmitBatchGetSizeBlocksCommits, @@ -46,7 +46,7 @@ func SubmitLoopInner( bytesProduced chan int, // a channel of block and commit bytes produced maxBatchSkew time.Duration, // max number of blocks that submitter is allowed to have pending unsubmittedBlocksNum func() uint64, - unsubmittedBlocksTime func() time.Duration, + skewTime func() time.Duration, maxBatchTime time.Duration, // max time to allow between batches maxBatchBytes uint64, // max size of serialised batch in bytes createAndSubmitBatch func(maxSizeBytes uint64) (sizeBlocksCommits uint64, err error), @@ -62,8 +62,7 @@ func SubmitLoopInner( // 'trigger': this thread is responsible for waking up the submitter when a new block arrives, and back-pressures the block production loop // if it gets too far ahead. for { - skewTime := unsubmittedBlocksTime() - if maxBatchSkew < skewTime { + if maxBatchSkew < skewTime() { // too much stuff is pending submission // we block here until we get a progress nudge from the submitter thread select { @@ -83,7 +82,7 @@ func SubmitLoopInner( types.RollappPendingSubmissionsSkewBytes.Set(float64(pendingBytes.Load())) types.RollappPendingSubmissionsSkewBlocks.Set(float64(unsubmittedBlocksNum())) - types.RollappPendingSubmissionsSkewTimeHours.Set(float64(skewTime.Hours())) + types.RollappPendingSubmissionsSkewTimeHours.Set(float64(skewTime().Hours())) submitter.Nudge() } @@ -100,19 +99,17 @@ func SubmitLoopInner( case <-submitter.C: } pending := pendingBytes.Load() - skewTime := unsubmittedBlocksTime() types.RollappPendingSubmissionsSkewBytes.Set(float64(pendingBytes.Load())) types.RollappPendingSubmissionsSkewBlocks.Set(float64(unsubmittedBlocksNum())) - types.RollappPendingSubmissionsSkewTimeHours.Set(float64(skewTime.Hours())) + types.RollappPendingSubmissionsSkewTimeHours.Set(float64(skewTime().Hours())) // while there are accumulated blocks, create and submit batches!! for { done := ctx.Err() != nil nothingToSubmit := pending == 0 - skewTime := unsubmittedBlocksTime() - lastSubmissionIsRecent := skewTime < maxBatchTime + lastSubmissionIsRecent := skewTime() < maxBatchTime maxDataNotExceeded := pending <= maxBatchBytes if done || nothingToSubmit || (lastSubmissionIsRecent && maxDataNotExceeded) { break @@ -288,18 +285,6 @@ func (m *Manager) GetUnsubmittedBlocks() uint64 { return m.State.Height() - m.LastSettlementHeight.Load() } -func (m *Manager) GetTimeSkew() time.Duration { - currentBlock, err := m.Store.LoadBlock(m.State.Height()) - if err != nil { - return time.Duration(0) - } - lastSubmittedBlock, err := m.Store.LoadBlock(m.LastSubmittedHeight.Load()) - if err != nil { - return time.Duration(0) - } - return currentBlock.Header.GetTimestamp().Sub(lastSubmittedBlock.Header.GetTimestamp()) -} - // UpdateLastSubmittedHeight will update last height submitted height upon events. // This may be necessary in case we crashed/restarted before getting response for our submission to the settlement layer. func (m *Manager) UpdateLastSubmittedHeight(event pubsub.Message) { diff --git a/block/submit_test.go b/block/submit_test.go index f07d16a45..46016174c 100644 --- a/block/submit_test.go +++ b/block/submit_test.go @@ -259,6 +259,7 @@ func TestSubmissionByTime(t *testing.T) { manager.DAClient = testutil.GetMockDALC(log.TestingLogger()) manager.Retriever = manager.DAClient.(da.BatchRetriever) + manager.State.LastSubmittedBlockTime = time.Now() // Check initial height initialHeight := uint64(0) require.Equal(initialHeight, manager.State.Height()) @@ -331,6 +332,7 @@ func TestSubmissionByBatchSize(t *testing.T) { managerConfig.BatchSubmitBytes = c.blockBatchMaxSizeBytes manager, err := testutil.GetManager(managerConfig, nil, 1, 1, 0, proxyApp, nil) require.NoError(err) + manager.State.LastSubmittedBlockTime = time.Now() manager.DAClient = testutil.GetMockDALC(log.TestingLogger()) manager.Retriever = manager.DAClient.(da.BatchRetriever) diff --git a/proto/types/dymint/state.proto b/proto/types/dymint/state.proto index 48f243594..b34db00d5 100755 --- a/proto/types/dymint/state.proto +++ b/proto/types/dymint/state.proto @@ -48,6 +48,9 @@ message State { // Proposer is a sequencer that acts as a proposer. Can be nil if no proposer is set. Sequencer proposer = 20; + + google.protobuf.Timestamp last_submitted_block_time = 21 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; + } //rollapp params defined in genesis and updated via gov proposal diff --git a/types/pb/dymint/state.pb.go b/types/pb/dymint/state.pb.go index 16f5b2548..0d4c4a6bd 100644 --- a/types/pb/dymint/state.pb.go +++ b/types/pb/dymint/state.pb.go @@ -46,7 +46,8 @@ type State struct { RollappParams RollappParams `protobuf:"bytes,18,opt,name=rollapp_params,json=rollappParams,proto3" json:"rollapp_params"` LastHeaderHash []byte `protobuf:"bytes,19,opt,name=last_header_hash,json=lastHeaderHash,proto3" json:"last_header_hash,omitempty"` // Proposer is a sequencer that acts as a proposer. Can be nil if no proposer is set. - Proposer *Sequencer `protobuf:"bytes,20,opt,name=proposer,proto3" json:"proposer,omitempty"` + Proposer *Sequencer `protobuf:"bytes,20,opt,name=proposer,proto3" json:"proposer,omitempty"` + LastSubmittedBlockTime time.Time `protobuf:"bytes,21,opt,name=last_submitted_block_time,json=lastSubmittedBlockTime,proto3,stdtime" json:"last_submitted_block_time"` } func (m *State) Reset() { *m = State{} } @@ -188,6 +189,13 @@ func (m *State) GetProposer() *Sequencer { return nil } +func (m *State) GetLastSubmittedBlockTime() time.Time { + if m != nil { + return m.LastSubmittedBlockTime + } + return time.Time{} +} + //rollapp params defined in genesis and updated via gov proposal type RollappParams struct { //data availability type (e.g. celestia) used in the rollapp @@ -251,50 +259,52 @@ func init() { func init() { proto.RegisterFile("types/dymint/state.proto", fileDescriptor_4b679420add07272) } var fileDescriptor_4b679420add07272 = []byte{ - // 686 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x94, 0xd1, 0x4e, 0xdb, 0x3c, - 0x14, 0xc7, 0x9b, 0x12, 0xda, 0xd4, 0xa5, 0x6d, 0x30, 0x7c, 0x52, 0xe0, 0x93, 0xd2, 0xc2, 0xb4, - 0xa9, 0x9a, 0xb4, 0x54, 0x1a, 0x0f, 0xb0, 0x29, 0x70, 0x41, 0x2b, 0x2e, 0x26, 0x77, 0xe2, 0x62, - 0x37, 0x91, 0x9b, 0x78, 0x49, 0xb4, 0x34, 0xce, 0x6c, 0x17, 0x8d, 0x3d, 0x05, 0x8f, 0xc5, 0x25, - 0x97, 0xbb, 0x62, 0x53, 0xb9, 0xdd, 0x43, 0x4c, 0xb6, 0x93, 0xd2, 0xaa, 0xe2, 0x0a, 0xf2, 0x3f, - 0x3f, 0xff, 0x7d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, 0xd7, 0xf8, 0xb3, 0x74, 0x8d, 0xbb, 0x27, 0xb7, 0xf6, 0xf0, 0xe4, 0xd6, 0x7e, 0x3d, - 0xb9, 0xb5, 0x2f, 0x5e, 0x9c, 0x8a, 0x64, 0x31, 0xf3, 0x42, 0x3a, 0x97, 0x3b, 0x4e, 0x72, 0xc9, - 0xff, 0xb8, 0xfd, 0x59, 0xed, 0x7d, 0xf9, 0xe3, 0x31, 0x2b, 0xbf, 0x67, 0x0d, 0x35, 0xd8, 0x67, - 0xff, 0x02, 0x00, 0x00, 0xff, 0xff, 0xf4, 0x93, 0x2f, 0x96, 0x2f, 0x05, 0x00, 0x00, + // 709 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x94, 0xcf, 0x6e, 0xda, 0x30, + 0x1c, 0xc7, 0x09, 0x4d, 0x4b, 0x30, 0x05, 0x52, 0xb7, 0x9d, 0x42, 0x27, 0x05, 0xda, 0x69, 0x13, + 0x9a, 0xb4, 0x20, 0xad, 0x0f, 0xb0, 0x29, 0xed, 0xa1, 0xa0, 0x1e, 0xa6, 0x30, 0xf5, 0xb0, 0x4b, + 0x64, 0x12, 0x8f, 0x58, 0x0b, 0x71, 0x66, 0x9b, 0x6a, 0xdd, 0x53, 0xf4, 0xb1, 0x7a, 0x99, 0xd4, + 0xe3, 0x4e, 0xdd, 0x44, 0x5f, 0x64, 0xb2, 0x9d, 0x50, 0x10, 0xea, 0x61, 0x27, 0xc8, 0xf7, 0xf7, + 0xc9, 0xd7, 0xbf, 0x7f, 0x0e, 0x70, 0xc4, 0x4d, 0x8e, 0xf9, 0x20, 0xbe, 0x99, 0x91, 0x4c, 0x0c, + 0xb8, 0x40, 0x02, 0x7b, 0x39, 0xa3, 0x82, 0xc2, 0x1d, 0xad, 0x1d, 0x1d, 0x4c, 0xe9, 0x94, 0x2a, + 0x69, 0x20, 0xff, 0xe9, 0xe8, 0x51, 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 0x2f, 0xde, 0x94, 0x88, 0x64, 0x3e, 0xf1, + 0x22, 0x3a, 0x93, 0x1f, 0x11, 0x9c, 0x49, 0xfe, 0xc7, 0xcd, 0xcf, 0xf2, 0xc3, 0x52, 0x7c, 0x9d, + 0x26, 0xc5, 0xf3, 0x64, 0x47, 0xd5, 0x77, 0xfa, 0x2f, 0x00, 0x00, 0xff, 0xff, 0x88, 0x56, 0x9c, + 0x4e, 0x90, 0x05, 0x00, 0x00, } func (m *State) Marshal() (dAtA []byte, err error) { @@ -317,6 +327,16 @@ func (m *State) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.LastSubmittedBlockTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.LastSubmittedBlockTime):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintState(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xaa if m.Proposer != nil { { size, err := m.Proposer.MarshalToSizedBuffer(dAtA[:i]) @@ -400,12 +420,12 @@ func (m *State) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x4a } - n5, err5 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.LastBlockTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.LastBlockTime):]) - if err5 != nil { - return 0, err5 + n6, err6 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.LastBlockTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.LastBlockTime):]) + if err6 != nil { + return 0, err6 } - i -= n5 - i = encodeVarintState(dAtA, i, uint64(n5)) + i -= n6 + i = encodeVarintState(dAtA, i, uint64(n6)) i-- dAtA[i] = 0x32 { @@ -550,6 +570,8 @@ func (m *State) Size() (n int) { l = m.Proposer.Size() n += 2 + l + sovState(uint64(l)) } + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.LastSubmittedBlockTime) + n += 2 + l + sovState(uint64(l)) return n } @@ -1054,6 +1076,39 @@ func (m *State) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 21: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LastSubmittedBlockTime", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowState + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthState + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthState + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.LastSubmittedBlockTime, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipState(dAtA[iNdEx:]) diff --git a/types/serialization.go b/types/serialization.go index aae805a1b..6bd9176bc 100644 --- a/types/serialization.go +++ b/types/serialization.go @@ -261,17 +261,18 @@ func (s *State) ToProto() (*pb.State, error) { } return &pb.State{ - Version: &s.Version, - ChainId: s.ChainID, - InitialHeight: int64(s.InitialHeight), - LastBlockHeight: int64(s.Height()), - LastBlockTime: s.LastBlockTime, - ConsensusParams: s.ConsensusParams, - LastResultsHash: s.LastResultsHash[:], - LastHeaderHash: s.LastHeaderHash[:], - AppHash: s.AppHash[:], - RollappParams: s.RollappParams, - Proposer: proposerProto, + Version: &s.Version, + ChainId: s.ChainID, + InitialHeight: int64(s.InitialHeight), + LastBlockHeight: int64(s.Height()), + LastBlockTime: s.LastBlockTime, + ConsensusParams: s.ConsensusParams, + LastResultsHash: s.LastResultsHash[:], + LastHeaderHash: s.LastHeaderHash[:], + AppHash: s.AppHash[:], + RollappParams: s.RollappParams, + Proposer: proposerProto, + LastSubmittedBlockTime: s.LastSubmittedBlockTime, }, nil } @@ -298,7 +299,7 @@ func (s *State) FromProto(other *pb.State) error { copy(s.AppHash[:], other.AppHash) s.RollappParams = other.RollappParams s.LastBlockTime = other.LastBlockTime - + s.LastSubmittedBlockTime = other.LastSubmittedBlockTime return nil } diff --git a/types/state.go b/types/state.go index ed66b008c..ee93311c3 100644 --- a/types/state.go +++ b/types/state.go @@ -106,6 +106,9 @@ func (s *State) NextHeight() uint64 { } func (s *State) GetSkewTime() time.Duration { + if s.LastBlockTime.Before(s.LastSubmittedBlockTime) { + return 0 + } return s.LastBlockTime.Sub(s.LastSubmittedBlockTime) }