-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Websockets #52
Merged
Merged
Websockets #52
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
12814db
rpc: use gorilla websockets
ebuchman 8e24b12
rpc: first successful websocket event subscription
ebuchman 85661de
fire events, event urls
ebuchman 2e918e8
rpc: websocket events testing
ebuchman 860d547
rpc: use NewBlock event in rpc tests
ebuchman b4388ae
vm: eventable and flip fix on CALL address
ebuchman 34098ed
state: fireEvents flag on ExecTx and fixes for GetAccount
ebuchman 9b76cfe
rpc: cleanup tests and test contract calls
ebuchman a1c5e32
fixes from review with jae
ebuchman d27e0bb
event cache and fireable interace
ebuchman 75049ec
major flippage for vm addrs. now left padded words for tx_cache
ebuchman 65f6691
more fixes from review
ebuchman 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
event cache and fireable interace
- Loading branch information
commit d27e0bbad578945bd8ece6f0386df8c9e98b2f57
There are no files selected for viewing
This file contains 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 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 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 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,39 @@ | ||
package events | ||
|
||
const ( | ||
eventsBufferSize = 1000 | ||
) | ||
|
||
// An EventCache buffers events for a Fireable | ||
// All events are cached. Filtering happens on Flush | ||
type EventCache struct { | ||
evsw Fireable | ||
events []eventInfo | ||
} | ||
|
||
// Create a new EventCache with an EventSwitch as backend | ||
func NewEventCache(evsw Fireable) *EventCache { | ||
return &EventCache{ | ||
evsw: evsw, | ||
events: make([]eventInfo, eventsBufferSize), | ||
} | ||
} | ||
|
||
// a cached event | ||
type eventInfo struct { | ||
event string | ||
msg interface{} | ||
} | ||
|
||
// Cache an event to be fired upon finality. | ||
func (evc *EventCache) FireEvent(event string, msg interface{}) { | ||
// append to list | ||
evc.events = append(evc.events, eventInfo{event, msg}) | ||
} | ||
|
||
// Fire events by running evsw.FireEvent on all cached events. Blocks. | ||
func (evc *EventCache) Flush() { | ||
for _, ei := range evc.events { | ||
evc.evsw.FireEvent(ei.event, ei.msg) | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -36,7 +36,7 @@ type State struct { | |
accounts merkle.Tree // Shouldn't be accessed directly. | ||
validatorInfos merkle.Tree // Shouldn't be accessed directly. | ||
|
||
evsw *events.EventSwitch | ||
evc events.Fireable // typically an events.EventCache | ||
} | ||
|
||
func LoadState(db dbm.DB) *State { | ||
|
@@ -101,7 +101,6 @@ func (s *State) Copy() *State { | |
UnbondingValidators: s.UnbondingValidators.Copy(), // copy the valSet lazily. | ||
accounts: s.accounts.Copy(), | ||
validatorInfos: s.validatorInfos.Copy(), | ||
evsw: s.evsw, | ||
} | ||
} | ||
|
||
|
@@ -119,7 +118,8 @@ func (s *State) Hash() []byte { | |
// Mutates the block in place and updates it with new state hash. | ||
func (s *State) SetBlockStateHash(block *types.Block) error { | ||
sCopy := s.Copy() | ||
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. be nice to have evc: nil on state.Copy() |
||
err := execBlock(sCopy, block, types.PartSetHeader{}, false) // don't fire events | ||
// sCopy has no event cache in it, so this won't fire events | ||
err := execBlock(sCopy, block, types.PartSetHeader{}) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -268,9 +268,9 @@ func (s *State) LoadStorage(hash []byte) (storage merkle.Tree) { | |
// State.storage | ||
//------------------------------------- | ||
|
||
// implements events.Eventable | ||
func (s *State) SetEventSwitch(evsw *events.EventSwitch) { | ||
s.evsw = evsw | ||
// Implements events.Eventable. Typically uses events.EventCache | ||
func (s *State) SetFireable(evc events.Fireable) { | ||
s.evc = evc | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
|
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.
clear out the evc.events