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

Pulled the contract updates from snapshots, removed by block filtering #1569

Open
wants to merge 3 commits into
base: node-updates-plugin-l2
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions pkg/blockchaininfo/blockchaininfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestChangesGenerationNewEntries(t *testing.T) {
}

equal, changes, err := blockchaininfo.CompareBUpdatesInfo(currentBlockInfo, previousBlockInfo,
proto.TestNetScheme, 10)
proto.TestNetScheme)
if err != nil {
return
}
Expand Down Expand Up @@ -183,7 +183,7 @@ func TestChangesGenerationContainsPrevious(t *testing.T) {
}

equal, changes, err := blockchaininfo.CompareBUpdatesInfo(currentBlockInfo, previousBlockInfo,
proto.TestNetScheme, 10)
proto.TestNetScheme)
if err != nil {
return
}
Expand Down Expand Up @@ -245,7 +245,7 @@ func TestNoChangesGeneration(t *testing.T) {
}

equal, changes, err := blockchaininfo.CompareBUpdatesInfo(currentBlockInfo, previousBlockInfo,
proto.TestNetScheme, 10)
proto.TestNetScheme)
if err != nil {
return
}
Expand Down
1 change: 0 additions & 1 deletion pkg/blockchaininfo/nats_publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ func handleBlockchainUpdate(updates BUpdatesInfo, bu *BUpdatesExtensionState, sc
bu.currentState = &updates
if bu.previousState == nil {
// publish initial updates

filteredDataEntries, err := filterDataEntries(updates.BlockUpdatesInfo.Height-bu.Limit,
updates.ContractUpdatesInfo.AllDataEntries)
if err != nil {
Expand Down
18 changes: 3 additions & 15 deletions pkg/blockchaininfo/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ type BUpdatesInfo struct {
// TODO wrap errors.

func CompareBUpdatesInfo(current, previous BUpdatesInfo,
scheme proto.Scheme, heightLimit uint64) (bool, BUpdatesInfo, error) {
scheme proto.Scheme) (bool, BUpdatesInfo, error) {
changes := BUpdatesInfo{
BlockUpdatesInfo: BlockUpdatesInfo{},
ContractUpdatesInfo: L2ContractDataEntries{},
}

equal := true
// todo REMOVE POINTERS
if current.BlockUpdatesInfo.Height != previous.BlockUpdatesInfo.Height {
equal = false
changes.BlockUpdatesInfo.Height = current.BlockUpdatesInfo.Height
Expand All @@ -58,22 +57,11 @@ func CompareBUpdatesInfo(current, previous BUpdatesInfo,
changes.BlockUpdatesInfo.BlockHeader = current.BlockUpdatesInfo.BlockHeader
}

previousFilteredDataEntries, err := filterDataEntries(previous.BlockUpdatesInfo.Height-heightLimit,
equalEntries, dataEntryChanges, err := compareDataEntries(current.ContractUpdatesInfo.AllDataEntries,
previous.ContractUpdatesInfo.AllDataEntries)
if err != nil {
return false, BUpdatesInfo{}, err
}
currentFilteredDataEntries, err := filterDataEntries(current.BlockUpdatesInfo.Height-heightLimit,
current.ContractUpdatesInfo.AllDataEntries)
if err != nil {
return false, BUpdatesInfo{}, err
}

equalEntries, dataEntryChanges, err := compareDataEntries(currentFilteredDataEntries,
previousFilteredDataEntries)
if err != nil {
return false, BUpdatesInfo{}, err
}
if !equalEntries {
equal = false
changes.ContractUpdatesInfo.AllDataEntries = dataEntryChanges
Expand Down Expand Up @@ -152,5 +140,5 @@ func compareDataEntries(current, previous proto.DataEntries) (bool, []proto.Data
}

func statesEqual(state BUpdatesExtensionState, scheme proto.Scheme) (bool, BUpdatesInfo, error) {
return CompareBUpdatesInfo(*state.currentState, *state.previousState, scheme, state.Limit)
return CompareBUpdatesInfo(*state.currentState, *state.previousState, scheme)
}
31 changes: 17 additions & 14 deletions pkg/state/appender.go
Original file line number Diff line number Diff line change
Expand Up @@ -846,12 +846,7 @@ func (a *txAppender) appendBlock(params *appendBlockParams) error {
if a.bUpdatesExtension != nil && a.bUpdatesExtension.EnableBlockchainUpdatesPlugin() {
// TODO get info from block snapshot?

// blockSnapshot.TxSnapshots.

updtErr := a.updateBlockchainUpdateInfo(blockInfo, params.block)
if updtErr != nil {
return updtErr
}
a.updateBlockchainUpdateInfo(blockInfo, params.block, blockSnapshot)
}

// check whether the calculated snapshot state hash equals with the provided one
Expand All @@ -875,12 +870,8 @@ func (a *txAppender) appendBlock(params *appendBlockParams) error {
return a.blockDiffer.saveCurFeeDistr(params.block)
}

func (a *txAppender) updateBlockchainUpdateInfo(blockInfo *proto.BlockInfo, blockHeader *proto.BlockHeader) error {
// TODO improve this by using diffs instead grabbing all the records every time
dataEntries, err := a.ia.state.RetrieveEntries(proto.NewRecipientFromAddress(a.bUpdatesExtension.L2ContractAddress()))
if err != nil && !errors.Is(err, proto.ErrNotFound) {
return err
}
func (a *txAppender) updateBlockchainUpdateInfo(blockInfo *proto.BlockInfo, blockHeader *proto.BlockHeader,
blockSnapshot proto.BlockSnapshot) {
blockID := blockHeader.BlockID()
bUpdatesInfo := blockchaininfo.BUpdatesInfo{
BlockUpdatesInfo: blockchaininfo.BlockUpdatesInfo{
Expand All @@ -890,12 +881,24 @@ func (a *txAppender) updateBlockchainUpdateInfo(blockInfo *proto.BlockInfo, bloc
BlockHeader: *blockHeader,
},
ContractUpdatesInfo: blockchaininfo.L2ContractDataEntries{
AllDataEntries: dataEntries,
AllDataEntries: nil,
Height: blockInfo.Height,
},
}
// Write the L2 contract updates into the structure.
l2ContractCount := 0
for _, txSnapshots := range blockSnapshot.TxSnapshots {
for _, snapshot := range txSnapshots {
if dataEntriesSnapshot, ok := snapshot.(*proto.DataEntriesSnapshot); ok {
if dataEntriesSnapshot.Address == a.bUpdatesExtension.L2ContractAddress() {
l2ContractCount++
bUpdatesInfo.ContractUpdatesInfo.AllDataEntries = append(bUpdatesInfo.ContractUpdatesInfo.AllDataEntries,
dataEntriesSnapshot.DataEntries...)
}
}
}
}
a.bUpdatesExtension.WriteBUpdates(bUpdatesInfo)
return nil
}

func (a *txAppender) createCheckerInfo(params *appendBlockParams) (*checkerInfo, error) {
Expand Down
Loading