doc: add explanation doc for fromExtWitness

This commit is contained in:
Halimao 2024-07-01 09:39:17 +08:00
parent dac70fe3a4
commit 1333352848

View file

@ -51,6 +51,9 @@ func (w *Witness) toExtWitness() *extWitness {
} }
// fromExtWitness converts the consensus witness format into our internal one. // fromExtWitness converts the consensus witness format into our internal one.
// This function is only used in decoding an already-constructed witness object
// which will be received from a remote source in the future. Although this does
// modify `w.State`, the lock is unnecessary here.
func (w *Witness) fromExtWitness(ext *extWitness) error { func (w *Witness) fromExtWitness(ext *extWitness) error {
w.Block, w.Headers = ext.Block, ext.Headers w.Block, w.Headers = ext.Block, ext.Headers
@ -58,8 +61,6 @@ func (w *Witness) fromExtWitness(ext *extWitness) error {
for _, code := range ext.Codes { for _, code := range ext.Codes {
w.Codes[string(code)] = struct{}{} w.Codes[string(code)] = struct{}{}
} }
w.lock.Lock()
defer w.lock.Unlock()
w.State = make(map[string]struct{}, len(ext.State)) w.State = make(map[string]struct{}, len(ext.State))
for _, node := range ext.State { for _, node := range ext.State {
w.State[string(node)] = struct{}{} w.State[string(node)] = struct{}{}