-
Notifications
You must be signed in to change notification settings - Fork 48
Support rollback #1610
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
Support rollback #1610
Changes from all commits
3c96588
fe0c741
92c4c86
733877b
cf38df8
fc73cfc
115dbde
4c72e74
5c688d1
dcc26ff
671e4a3
27538ae
36abdb3
038867d
b054123
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
quiet: False | ||
dir: "{{.InterfaceDir}}/mocks" | ||
mockname: "Mock{{.InterfaceName}}" | ||
with-expecter: true | ||
issue-845-fix: True | ||
filename: "{{.InterfaceName | snakecase}}.go" | ||
|
||
packages: | ||
|
@@ -9,3 +10,6 @@ packages: | |
Header: | ||
Protocol: | ||
Handler: | ||
github.com/wavesplatform/gowaves/pkg/blockchaininfo: | ||
interfaces: | ||
UpdatesPublisherInterface: | ||
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. Newline |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -371,6 +371,20 @@ func run(nc *config) (retErr error) { | |
return nil | ||
} | ||
|
||
func initBlockchainUpdatesPlugin(ctx context.Context, | ||
l2addressContract string, | ||
enableBlockchainUpdatesPlugin bool, | ||
updatesChannel chan<- proto.BUpdatesInfo, firstBlock *bool, | ||
) (*proto.BlockchainUpdatesPluginInfo, error) { | ||
l2address, cnvrtErr := proto.NewAddressFromString(l2addressContract) | ||
if cnvrtErr != nil { | ||
return nil, errors.Wrapf(cnvrtErr, "failed to convert L2 contract address %q", l2addressContract) | ||
} | ||
bUpdatesPluginInfo := proto.NewBlockchainUpdatesPluginInfo(ctx, l2address, updatesChannel, | ||
firstBlock, enableBlockchainUpdatesPlugin) | ||
return bUpdatesPluginInfo, nil | ||
} | ||
|
||
func runNode(ctx context.Context, nc *config) (_ io.Closer, retErr error) { | ||
cfg, err := blockchainSettings(nc) | ||
if err != nil { | ||
|
@@ -402,25 +416,44 @@ func runNode(ctx context.Context, nc *config) (_ io.Closer, retErr error) { | |
return nil, errors.Wrap(err, "failed to create state parameters") | ||
} | ||
|
||
updatesChannel := make(chan proto.BUpdatesInfo) | ||
extensionReady := make(chan struct{}) | ||
firstBlock := false | ||
bUpdatesPluginInfo, initErr := initBlockchainUpdatesPlugin(ctx, nc.BlockchainUpdatesL2Address, | ||
nc.enableBlockchainUpdatesPlugin, updatesChannel, &firstBlock) | ||
if initErr != nil { | ||
return nil, errors.Wrap(err, "failed to initialize blockchain updates plugin") | ||
} | ||
st, err := state.NewState(path, true, params, cfg, nc.enableLightMode, bUpdatesPluginInfo) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to initialize node's state") | ||
} | ||
defer func() { retErr = closeIfErrorf(st, retErr, "failed to close state") }() | ||
go func() { | ||
<-extensionReady | ||
bUpdatesPluginInfo.MakeExtensionReady() | ||
close(extensionReady) | ||
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. Only the writer which owns the channel should close it. 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. Done. I've never tried it before, will you double check it please? |
||
}() | ||
|
||
var bUpdatesExtension *blockchaininfo.BlockchainUpdatesExtension | ||
if nc.enableBlockchainUpdatesPlugin { | ||
var bUErr error | ||
bUpdatesExtension, bUErr = runBlockchainUpdatesPlugin(ctx, cfg, nc.BlockchainUpdatesL2Address) | ||
bUpdatesExtension, bUErr = initializeBlockchainUpdatesExtension(ctx, cfg, nc.BlockchainUpdatesL2Address, | ||
updatesChannel, &firstBlock, st, extensionReady) | ||
if bUErr != nil { | ||
return nil, errors.Wrap(bUErr, "failed to run blockchain updates plugin") | ||
} | ||
go bUpdatesExtension.ReceiveSignals() | ||
go func() { | ||
publshrErr := bUpdatesExtension.RunBlockchainUpdatesPublisher(ctx, | ||
cfg.AddressSchemeCharacter) | ||
if publshrErr != nil { | ||
zap.S().Fatalf("Failed to run blockchain updates publisher: %v", publshrErr) | ||
} | ||
}() | ||
zap.S().Info("The blockchain info extension started pulling info from smart contract address", | ||
nc.BlockchainUpdatesL2Address) | ||
} | ||
|
||
// Send updatesChannel into BlockchainSettings. Write updates into this channel | ||
st, err := state.NewState(path, true, params, cfg, nc.enableLightMode, bUpdatesExtension) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to initialize node's state") | ||
} | ||
defer func() { retErr = closeIfErrorf(st, retErr, "failed to close state") }() | ||
|
||
features, err := minerFeatures(st, nc.minerVoteFeatures) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to parse and validate miner features") | ||
|
@@ -817,34 +850,30 @@ func runAPIs( | |
return nil | ||
} | ||
|
||
func runBlockchainUpdatesPlugin( | ||
func initializeBlockchainUpdatesExtension( | ||
ctx context.Context, | ||
cfg *settings.BlockchainSettings, | ||
l2ContractAddress string, | ||
updatesChannel chan proto.BUpdatesInfo, | ||
firstBlock *bool, | ||
state state.State, | ||
extensionReady chan<- struct{}, | ||
) (*blockchaininfo.BlockchainUpdatesExtension, error) { | ||
l2address, cnvrtErr := proto.NewAddressFromString(l2ContractAddress) | ||
if cnvrtErr != nil { | ||
return nil, errors.Wrapf(cnvrtErr, "failed to convert L2 contract address %q", l2ContractAddress) | ||
} | ||
|
||
bUpdatesExtensionState := blockchaininfo.NewBUpdatesExtensionState( | ||
bUpdatesExtensionState, err := blockchaininfo.NewBUpdatesExtensionState( | ||
blockchaininfo.StoreBlocksLimit, | ||
cfg.AddressSchemeCharacter, | ||
l2ContractAddress, | ||
state, | ||
) | ||
|
||
updatesChannel := make(chan blockchaininfo.BUpdatesInfo) | ||
requestsChannel := make(chan blockchaininfo.L2Requests) | ||
go func() { | ||
err := bUpdatesExtensionState.RunBlockchainUpdatesPublisher(ctx, updatesChannel, | ||
cfg.AddressSchemeCharacter, requestsChannel) | ||
if err != nil { | ||
zap.S().Fatalf("Failed to run blockchain updates publisher: %v", err) | ||
} | ||
}() | ||
|
||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to initialize blockchain updates extension state") | ||
} | ||
l2address, cnvrtErr := proto.NewAddressFromString(l2ContractAddress) | ||
if cnvrtErr != nil { | ||
return nil, errors.Wrapf(cnvrtErr, "failed to convert L2 contract address %q", l2ContractAddress) | ||
} | ||
return blockchaininfo.NewBlockchainUpdatesExtension(ctx, l2address, updatesChannel, | ||
requestsChannel, bUpdatesExtensionState), nil | ||
bUpdatesExtensionState, firstBlock, extensionReady), nil | ||
} | ||
|
||
func FromArgs(scheme proto.Scheme, c *config) func(s *settings.NodeSettings) error { | ||
|
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.
Can you explain the changes, please?
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.
I'll return it back, something wasn't working with that line, but it does now