transaction: microoptimize multiattribute check

We can't have more than 256 attribute types, so allocate and use 32 bytes
instead of a whole map.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
This commit is contained in:
Roman Khimov 2024-08-24 21:57:22 +03:00
parent f15a163cdf
commit e8a86e617b

View file

@ -14,6 +14,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/util/bitfield"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
)
@ -428,14 +429,14 @@ func (t *Transaction) isValid() error {
}
}
}
attrs := map[AttrType]bool{}
var attrBits = bitfield.New(256)
for i := range t.Attributes {
typ := t.Attributes[i].Type
if !typ.allowMultiple() {
if attrs[typ] {
if attrBits.IsSet(int(typ)) {
return fmt.Errorf("%w: multiple '%s' attributes", ErrInvalidAttribute, typ.String())
}
attrs[typ] = true
attrBits.Set(int(typ))
}
}
if len(t.Script) == 0 {