-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add queue for block proposal, remove consensus ready signal
- Loading branch information
1 parent
3580e89
commit 872e519
Showing
12 changed files
with
477 additions
and
122 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package sttypes | ||
package types | ||
|
||
import ( | ||
"sync" | ||
|
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,134 @@ | ||
package consensus | ||
|
||
import ( | ||
"sync" | ||
"time" | ||
|
||
"github.com/harmony-one/harmony/internal/utils" | ||
) | ||
|
||
// ProposalType is to indicate the type of signal for new block proposal | ||
type ProposalType byte | ||
|
||
// Constant of the type of new block proposal | ||
const ( | ||
SyncProposal ProposalType = iota | ||
AsyncProposal | ||
) | ||
|
||
func (pt ProposalType) String() string { | ||
if pt == SyncProposal { | ||
return "SyncProposal" | ||
} | ||
return "AsyncProposal" | ||
} | ||
|
||
// Proposal represents a new block proposal with associated metadata | ||
type Proposal struct { | ||
Type ProposalType | ||
Caller string | ||
Height uint64 | ||
ViewID uint64 | ||
Source string | ||
Reason string | ||
CreatedAt time.Time | ||
lock *sync.RWMutex | ||
} | ||
|
||
// NewProposal creates a new proposal | ||
func NewProposal(t ProposalType, viewID uint64, height uint64, source string, reason string) *Proposal { | ||
return &Proposal{ | ||
Type: t, | ||
Caller: utils.GetCallStackInfo(2), | ||
ViewID: 0, | ||
Height: 0, | ||
Source: source, | ||
Reason: reason, | ||
CreatedAt: time.Now(), | ||
lock: &sync.RWMutex{}, | ||
} | ||
} | ||
|
||
// Clone returns a copy of proposal | ||
func (p *Proposal) Clone() *Proposal { | ||
p.lock.RLock() | ||
defer p.lock.RUnlock() | ||
return &Proposal{ | ||
Type: p.Type, | ||
Caller: p.Caller, | ||
ViewID: p.ViewID, | ||
Height: p.Height, | ||
CreatedAt: p.CreatedAt, | ||
lock: &sync.RWMutex{}, | ||
} | ||
} | ||
|
||
// GetType retrieves the Proposal type | ||
func (p *Proposal) GetType() ProposalType { | ||
p.lock.RLock() | ||
defer p.lock.RUnlock() | ||
return p.Type | ||
} | ||
|
||
// SetType updates the Proposal type | ||
func (p *Proposal) SetType(t ProposalType) { | ||
p.lock.Lock() | ||
defer p.lock.Unlock() | ||
p.Type = t | ||
} | ||
|
||
// GetCaller retrieves the Proposal caller | ||
func (p *Proposal) GetCaller() string { | ||
p.lock.RLock() | ||
defer p.lock.RUnlock() | ||
return p.Caller | ||
} | ||
|
||
// SetCaller updates the Proposal caller | ||
func (p *Proposal) SetCaller(caller string) { | ||
p.lock.Lock() | ||
defer p.lock.Unlock() | ||
p.Caller = caller | ||
} | ||
|
||
// GetHeight retrieves the Proposal height | ||
func (p *Proposal) GetHeight() uint64 { | ||
p.lock.RLock() | ||
defer p.lock.RUnlock() | ||
return p.Height | ||
} | ||
|
||
// SetHeight updates the Proposal height | ||
func (p *Proposal) SetHeight(height uint64) { | ||
p.lock.Lock() | ||
defer p.lock.Unlock() | ||
p.Height = height | ||
} | ||
|
||
// GetViewID retrieves the Proposal view ID | ||
func (p *Proposal) GetViewID() uint64 { | ||
p.lock.RLock() | ||
defer p.lock.RUnlock() | ||
return p.ViewID | ||
} | ||
|
||
// SetViewID updates the Proposal view ID | ||
func (p *Proposal) SetViewID(viewID uint64) { | ||
p.lock.Lock() | ||
defer p.lock.Unlock() | ||
p.ViewID = viewID | ||
} | ||
|
||
// GetCreatedAt retrieves the Proposal creation time | ||
func (p *Proposal) GetCreatedAt() time.Time { | ||
p.lock.RLock() | ||
defer p.lock.RUnlock() | ||
return p.CreatedAt | ||
} | ||
|
||
// SetCreatedAt updates the Proposal creation time | ||
func (p *Proposal) SetCreatedAt(createdAt time.Time) { | ||
p.lock.Lock() | ||
defer p.lock.Unlock() | ||
p.CreatedAt = createdAt | ||
} |
Oops, something went wrong.