-
Notifications
You must be signed in to change notification settings - Fork 44
Blockchain updates for L2 extension #1430
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
Open
esuwu
wants to merge
99
commits into
master
Choose a base branch
from
node-updates-plugin-l2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
99 commits
Select commit
Hold shift + click to select a range
63b159c
Initial draft
esuwu 69e9dbd
Changed a comment
esuwu b35bea1
moved a file
esuwu 27494ad
rename a folder
esuwu 983babc
Sent the updates channel into block appplier
esuwu 5272899
Added some design comments
esuwu 4fef6e3
Context in the updates function
esuwu dcd18f3
Merge branch 'master' into node-updates-plugin-l2
esuwu 3cc00d5
Added protobuf
esuwu 6752f8a
Moved proto, added conversion
esuwu bdc8854
Added state comparison
esuwu 19cc302
Added a draft for retrieving history entries
esuwu b6fb33c
Renamed a function
esuwu dca31ee
Fixed most of the linter issues
esuwu f524fe9
Merge branch 'master' into node-updates-plugin-l2
esuwu 18eab8c
Added paging
esuwu e2da71e
Added changes detector
esuwu da48829
Fixed a bug
esuwu b9318c2
Renamed functions
esuwu 1e91dac
Merged from main
esuwu 4dd8e5a
Merged from master
esuwu 59f75f3
Started writing the filter
esuwu 3a0ce55
Merged from master
esuwu 7b77774
Commented an unused function
esuwu 4d9419f
Added a basic filter
esuwu 6338578
Fixed filtering
esuwu 3d2bf74
Added tests
esuwu 9fe8ed9
Added tests and parameters for nats subscriber
esuwu e057d2a
Fixed tests and linter errors
esuwu b2a461c
Merged from master
esuwu 860b830
fixed gosec issues
esuwu ec15106
fixed one more gosec issue
esuwu 8f70624
Mod clean.
nickeskov c0652df
Merge branch 'master' into node-updates-plugin-l2
nickeskov 02f82ef
Fix lint for 'runNode' function.
nickeskov bb3bd64
Fix gosec issues.
nickeskov 47320cf
Deleted stale go protobuf generated code.
nickeskov fb56f6b
Make some types and functions package private.
nickeskov 89ffaf2
Update 'go.mod' go version.
nickeskov 28086dc
Change location of 'blockchaininfo_test.go'.
nickeskov 2f8c3c0
Add new method 'PartialBlockHeader' for 'ProtobufConverter'.
nickeskov 5f1010c
Refactor 'BUpdatesInfoFromProto' function with unused functions removal.
nickeskov 7dc0748
Refactored a bit 'L2ContractDataEntriesFromProto'.
nickeskov 42bf0ff
Merge branch 'master' into node-updates-plugin-l2
nickeskov 3f9bb83
Added a parse function
esuwu 5d37195
Merge branch 'master' into node-updates-plugin-l2
nickeskov cf23bdf
Set 'NoSigs' option for nats sever to true.
nickeskov d7dcd5e
Fix 'runPublisher' in case when updates channel is closed.
nickeskov d13b940
Add nats sever shutdown.
nickeskov 4dc94d5
Fix deadlock and refactoring.
nickeskov 214bd46
Merge branch 'master' into node-updates-plugin-l2
nickeskov 8fbe2b4
Fixed err not found handling
esuwu bb23dbc
Fixed a toolchain not found issue (#1545)
esuwu b65c6d9
Bump github.com/stretchr/testify from 1.9.0 to 1.10.0 (#1546)
dependabot[bot] 68db8b3
Handle blockchain import errors properly (#1548)
nickeskov d66423a
Bump github.com/elliotchance/orderedmap/v2 from 2.4.0 to 2.5.0 (#1549)
dependabot[bot] c598d67
Check on leasing state added. (#1550)
alexeykiselev bd889f5
Prepare timers for go1.23. (#1552)
nickeskov c24cb57
Peer address parsing refactoring (#1551)
nickeskov 6814098
Merge branch 'master' into node-updates-plugin-l2
esuwu b87f8ad
Left a todo
esuwu cdb6083
Merged from master
esuwu 7960470
Pulled the contract updates from snapshots, removed by block filterin…
esuwu a8fedad
merged from master
esuwu 673f800
Added nats requests functionality
esuwu a873866
When restarted, the previous state must be nil
esuwu 45523aa
Formatted a line correctly
esuwu 52377b4
Merged from master
esuwu fb0e42f
Fixed some review issues
esuwu c750bae
Added an unmarshal function for blockMeta
esuwu 6fd4d59
Write a test for a function that is not used, so the linter doesn't a…
esuwu 91b38a8
Merged from master
esuwu 9783694
Merge branch 'master' into node-updates-plugin-l2
esuwu c810622
Merge branch 'master' into node-updates-plugin-l2
esuwu 574bea9
Support rollback (#1610)
esuwu 62666ac
Merge branch 'master' into node-updates-plugin-l2
esuwu 4f17cf0
Fixed merging errors
esuwu 056639a
Fixed some issues from review
esuwu 5817157
Added a package level error
esuwu 30e1993
Returned a mock name line into mockery yaml
esuwu c1c3051
Fixed the rest of the isxues
esuwu 5716cb0
returned the state version back
esuwu 12aacda
Merged from master
esuwu 97ae1f0
Replaced a read Bytes to readFull
esuwu 3f0eb56
updated blockchain info proto scheme
esuwu e9bb59f
Renamed some functions
esuwu 6229b76
Fixed a ready condition and sending empty data entries
esuwu 5590d85
Changed the updates channel to a bufferized one
esuwu 0d9be2c
Fixed linter issues
esuwu 1853195
Merged from master
esuwu 0a06fe7
Updated the channel buffer size
esuwu 4af1096
Moved a variable initialization
esuwu 62b1b7d
Merged from master
esuwu 289346b
Moved some constants, added a test
esuwu c1bae62
removed the subscriber
esuwu c77aaa3
Merge branch 'master' into node-updates-plugin-l2
esuwu 019d4ad
Changed serialization
esuwu 78fb3c7
Merge branch 'master' into node-updates-plugin-l2
esuwu 87caeba
Merge branch 'master' into node-updates-plugin-l2
nickeskov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package blockchaininfo | ||
|
||
import ( | ||
"bytes" | ||
"encoding/binary" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/wavesplatform/gowaves/pkg/proto" | ||
) | ||
|
||
const EpochKeyPrefix = "epoch_" | ||
const blockMeta0xKeyPrefix = "block_0x" | ||
Comment on lines
+13
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be package private. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is package private? |
||
|
||
// Helper function to read uint64 from bytes. | ||
func readInt64(data *bytes.Reader) (int64, error) { | ||
var num int64 | ||
err := binary.Read(data, binary.BigEndian, &num) | ||
if err != nil { | ||
return 0, err | ||
} | ||
return num, nil | ||
} | ||
|
||
// Decode base64 and extract blockHeight and height. | ||
func extractEpochFromBlockMeta(blockMetaValue []byte) (int64, error) { | ||
var blockMeta BlockMeta | ||
err := blockMeta.UnmarshalBinary(blockMetaValue) | ||
if err != nil { | ||
return 0, errors.Errorf("failed to unmarshal blockMeta, %v", err) | ||
} | ||
|
||
return blockMeta.BlockEpoch, nil | ||
} | ||
|
||
func filterEpochEntry(entry proto.DataEntry, beforeHeight uint64) ([]proto.DataEntry, error) { | ||
key := entry.GetKey() | ||
// Extract the part after "epoch_" | ||
epochStr := key[len(EpochKeyPrefix):] | ||
|
||
epochNumber, err := strconv.ParseUint(epochStr, 10, 64) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Return this entry only if epochNumber is greater than beforeHeight | ||
if epochNumber > beforeHeight { | ||
return []proto.DataEntry{entry}, nil | ||
} | ||
return nil, nil | ||
} | ||
|
||
func filterBlock0xEntry(entry proto.DataEntry, beforeHeight uint64) ([]proto.DataEntry, error) { | ||
// Extract blockHeight and height from base64. | ||
binaryEntry, ok := entry.(*proto.BinaryDataEntry) | ||
if !ok { | ||
return nil, errors.New("failed to convert block meta key to binary data entry") | ||
} | ||
epoch, err := extractEpochFromBlockMeta(binaryEntry.Value) | ||
if err != nil { | ||
return nil, errors.Errorf("failed to filter data entries, %v", err) | ||
} | ||
|
||
if epoch < 0 { | ||
return nil, errors.New("epoch is less than 0") | ||
} | ||
// Return this entry only if epochNumber is greater than beforeHeight | ||
if uint64(epoch) > beforeHeight { | ||
return []proto.DataEntry{entry}, nil | ||
} | ||
return nil, nil | ||
} | ||
|
||
func filterDataEntries(beforeHeight uint64, dataEntries []proto.DataEntry) ([]proto.DataEntry, error) { | ||
var filteredDataEntries []proto.DataEntry | ||
|
||
for _, entry := range dataEntries { | ||
key := entry.GetKey() | ||
|
||
switch { | ||
// Filter "epoch_" prefixed keys. | ||
case strings.HasPrefix(key, EpochKeyPrefix): | ||
entryOrNil, err := filterEpochEntry(entry, beforeHeight) | ||
if err != nil { | ||
return nil, err | ||
} | ||
filteredDataEntries = append(filteredDataEntries, entryOrNil...) | ||
|
||
// Filter block_0x binary entries. | ||
case strings.HasPrefix(key, blockMeta0xKeyPrefix): | ||
entryOrNil, err := filterBlock0xEntry(entry, beforeHeight) | ||
if err != nil { | ||
return nil, err | ||
} | ||
filteredDataEntries = append(filteredDataEntries, entryOrNil...) | ||
|
||
// Default case to handle non-epoch and non-base64 entries. | ||
default: | ||
filteredDataEntries = append(filteredDataEntries, entry) | ||
} | ||
} | ||
|
||
return filteredDataEntries, nil | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if I want to receive updates from two or more chain contracts?
Maybe add
TODO
about it?